}
#endif
-void *b_malloc(char *file, int line, size_t size)
+void *b_malloc(const char *file, int line, size_t size)
{
void *buf;
/*
* Implement snprintf
*/
-int bsnprintf(char *str, size_t size, const char *fmt, ...)
+int bsnprintf(char *str, int32_t size, const char *fmt, ...)
{
#ifdef HAVE_VSNPRINTF
va_list arg_ptr;
/*
* Implement vsnprintf()
*/
-int bvsnprintf(char *str, size_t size, const char *format, va_list ap)
+int bvsnprintf(char *str, int32_t size, const char *format, va_list ap)
{
#ifdef HAVE_VSNPRINTF
int len;
#endif /* HAVE_LOCALTIME_R */
#ifndef HAVE_READDIR_R
-
+#ifndef HAVE_WIN32
#include <dirent.h>
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
}
V(mutex);
return stat;
-}
+}
+#endif
#endif /* HAVE_READDIR_R */
#ifdef xxxxxxxxxx_STRERROR_R
}
#endif /* DEBUG_MUTEX */
-#ifndef HAVE_CYGWIN
+#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
static int del_pid_file_ok = FALSE;
#endif
*/
void create_pid_file(char *dir, char *progname, int port)
{
-#ifndef HAVE_CYGWIN
+#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
int pidfd, len;
int oldpid;
char pidbuf[20];
struct stat statp;
Mmsg(&fname, "%s/%s.%d.pid", dir, progname, port);
- if (stat(fname, &statp) == 0) {
+ if (stat(mp_chr(fname), &statp) == 0) {
/* File exists, see what we have */
*pidbuf = 0;
- if ((pidfd = open(fname, O_RDONLY)) < 0 ||
+ if ((pidfd = open(mp_chr(fname), O_RDONLY)) < 0 ||
read(pidfd, &pidbuf, sizeof(pidbuf)) < 0 ||
sscanf(pidbuf, "%d", &oldpid) != 1) {
Emsg2(M_ERROR_TERM, 0, _("Cannot open pid file. %s ERR=%s\n"), fname, strerror(errno));
progname, oldpid, fname);
}
/* He is not alive, so take over file ownership */
- unlink(fname); /* remove stale pid file */
+ unlink(mp_chr(fname)); /* remove stale pid file */
}
/* Create new pid file */
- if ((pidfd = open(fname, O_CREAT | O_TRUNC | O_WRONLY, 0644)) >= 0) {
+ if ((pidfd = open(mp_chr(fname), O_CREAT | O_TRUNC | O_WRONLY, 0644)) >= 0) {
len = sprintf(pidbuf, "%d\n", (int)getpid());
write(pidfd, pidbuf, len);
close(pidfd);
*/
int delete_pid_file(char *dir, char *progname, int port)
{
-#ifndef HAVE_CYGWIN
+#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
POOLMEM *fname = get_pool_memory(PM_FNAME);
if (!del_pid_file_ok) {
}
del_pid_file_ok = FALSE;
Mmsg(&fname, "%s/%s.%d.pid", dir, progname, port);
- unlink(fname);
+ unlink(mp_chr(fname));
free_pool_memory(fname);
#endif
return 1;
static pthread_cond_t timer = PTHREAD_COND_INITIALIZER;
/*
- * This routine will sleep (sec, msec). Note, however, that if a
+ * This routine will sleep (sec, microsec). Note, however, that if a
* signal occurs, it will return early. It is up to the caller
* to recall this routine if he/she REALLY wants to sleep the
* requested time.
*/
-int bmicrosleep(time_t sec, long msec)
+int bmicrosleep(time_t sec, long usec)
{
struct timespec timeout;
struct timeval tv;
int stat;
timeout.tv_sec = sec;
- timeout.tv_nsec = msec * 1000;
+ timeout.tv_nsec = usec * 1000;
#ifdef HAVE_NANOSLEEP
stat = nanosleep(&timeout, NULL);
return (long long int)strtod(ptr, endptr);
}
#endif
+
+/*
+ * Bacula's implementation of fgets(). The difference is that it handles
+ * being interrupted by a signal (e.g. a SIGCHLD).
+ */
+#undef fgetc
+char *bfgets(char *s, int size, FILE *fd)
+{
+ char *p = s;
+ int ch;
+ *p = 0;
+ for (int i=0; i < size-1; i++) {
+ do {
+ errno = 0;
+ ch = fgetc(fd);
+ } while (ch == -1 && (errno == EINTR || errno == EAGAIN));
+ if (ch == -1) {
+ if (i == 0) {
+ return NULL;
+ } else {
+ return s;
+ }
+ }
+ *p++ = ch;
+ *p = 0;
+ if (ch == '\n') {
+ break;
+ }
+ }
+ return s;
+}
+
+/*
+ * Make a "unique" filename. It is important that if
+ * called again with the same "what" that the result
+ * will be identical. This allows us to use the file
+ * without saving its name, and re-generate the name
+ * so that it can be deleted.
+ */
+void make_unique_filename(POOLMEM **name, int Id, char *what)
+{
+ Mmsg(name, "%s/%s.%s.%d.tmp", working_directory, my_name, what, Id);
+}