* Version $Id$
*/
/*
- Copyright (C) 2000-2005 Kern Sibbald
+ Copyright (C) 2000-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
return dest;
}
+/*
+ * Allows one or both pointers to be NULL
+ */
+bool bstrcmp(const char *s1, const char *s2)
+{
+ if (s1 == s2) return true;
+ if (s1 == NULL || s2 == NULL) return false;
+ return strcmp(s1, s2) == 0;
+}
+
/*
* Get character length of UTF-8 string
*
buf = malloc(size);
if (buf == NULL) {
- Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), strerror(errno));
+ berrno be;
+ Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
}
return buf;
}
buf = malloc(size);
#endif
if (buf == NULL) {
- e_msg(file, line, M_ABORT, 0, _("Out of memory: ERR=%s\n"), strerror(errno));
+ berrno be;
+ e_msg(file, line, M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
}
return buf;
}
{
buf = realloc(buf, size);
if (buf == NULL) {
- Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), strerror(errno));
+ berrno be;
+ Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
}
return buf;
}
buf = calloc(size1, size2);
if (buf == NULL) {
- Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), strerror(errno));
+ berrno be;
+ Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
}
return buf;
}
{
int errstat;
+ /* Note, this trylock *should* fail if the mutex is locked */
if ((errstat=pthread_mutex_trylock(m)) == 0) {
berrno be;
e_msg(file, line, M_ERROR, 0, _("Mutex unlock not locked. ERR=%s\n"),
}
#endif
-#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
+#if !defined(HAVE_WIN32)
static int del_pid_file_ok = FALSE;
#endif
*/
void create_pid_file(char *dir, const char *progname, int port)
{
-#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
+#if !defined(HAVE_WIN32)
int pidfd, len;
int oldpid;
char pidbuf[20];
*/
int delete_pid_file(char *dir, const char *progname, int port)
{
-#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
+#if !defined(HAVE_WIN32)
POOLMEM *fname = get_pool_memory(PM_FNAME);
if (!del_pid_file_ok) {
0
};
+#ifdef HAVE_WIN32
+#undef open
+#undef read
+#undef write
+#undef lseek
+#undef close
+#undef O_BINARY
+#define open _open
+#define read _read
+#define write _write
+#define lseek _lseeki64
+#define close _close
+#define O_BINARY _O_BINARY
+#endif
+
/*
* Open and read the state file for the daemon
*/
Mmsg(&fname, "%s/%s.%d.state", dir, progname, port);
/* If file exists, see what we have */
// Dmsg1(10, "O_BINARY=%d\n", O_BINARY);
- if ((sfd = open(fname, O_RDONLY|O_BINARY, 0)) < 0) {
+ if ((sfd = open(fname, O_RDONLY|O_BINARY)) < 0) {
Dmsg3(010, "Could not open state file. sfd=%d size=%d: ERR=%s\n",
sfd, sizeof(hdr), strerror(errno));
goto bail_out;
Mmsg(&fname, "%s/%s.%d.state", dir, progname, port);
/* Create new state file */
+ unlink(fname);
if ((sfd = open(fname, O_CREAT|O_WRONLY|O_BINARY, 0640)) < 0) {
berrno be;
Dmsg2(000, "Could not create state file. %s ERR=%s\n", fname, be.strerror());
*p = 0;
}
else { /* Mac (\r only) */
- ungetc(ch, fd); /* Push next character back to fd */
+ (void)ungetc(ch, fd); /* Push next character back to fd */
}
break;
}