X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Flib%2Fbsys.c;h=548ab97b2a6fbdb4ba562230f641f709ada893cd;hb=3f8a3a045ea058657030f588a10f786449d00e0d;hp=9c1a29d353de795aa49e170977603beea6a4c19d;hpb=f8d22b03bb166b2b9bdb2e6f8196298d1de6ba2f;p=bacula%2Fbacula diff --git a/bacula/src/lib/bsys.c b/bacula/src/lib/bsys.c index 9c1a29d353..548ab97b2a 100644 --- a/bacula/src/lib/bsys.c +++ b/bacula/src/lib/bsys.c @@ -8,7 +8,7 @@ * 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 @@ -113,6 +113,16 @@ char *bstrncat(char *dest, POOL_MEM &src, int maxlen) 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 * @@ -173,7 +183,8 @@ void *bmalloc(size_t size) 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; } @@ -189,7 +200,8 @@ void *b_malloc(const char *file, int line, size_t size) 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; } @@ -199,7 +211,8 @@ void *brealloc (void *buf, size_t size) { 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; } @@ -211,7 +224,8 @@ void *bcalloc (size_t size1, size_t size2) 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; } @@ -482,6 +496,21 @@ static struct s_state_hdr state_hdr = { 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 */ @@ -497,7 +526,7 @@ void read_state_file(char *dir, const char *progname, int port) 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; @@ -543,6 +572,7 @@ void write_state_file(char *dir, const char *progname, int port) 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()); @@ -659,7 +689,7 @@ char *bfgets(char *s, int size, FILE *fd) *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; }