return dest;
}
+/*
+ * Guarantee that the string is properly terminated */
+char *bstrncpy(char *dest, POOL_MEM &src, int maxlen)
+{
+ strncpy(dest, src.c_str(), maxlen-1);
+ dest[maxlen-1] = 0;
+ return dest;
+}
+
+
char *bstrncat(char *dest, const char *src, int maxlen)
{
strncat(dest, src, maxlen-1);
return dest;
}
+char *bstrncat(char *dest, POOL_MEM &src, int maxlen)
+{
+ strncat(dest, src.c_str(), maxlen-1);
+ dest[maxlen-1] = 0;
+ return dest;
+}
+
+
#ifndef DEBUG
void *bmalloc(size_t size)
#else
- int len;
+ int len, buflen;
char *buf;
- buf = get_memory(BIG_BUF);
+ buflen = size > BIG_BUF ? size : BIG_BUF;
+ buf = get_memory(buflen);
len = vsprintf(buf, format, ap);
- if (len >= BIG_BUF) {
+ if (len >= buflen) {
Emsg0(M_ABORT, 0, _("Buffer overflow.\n"));
}
- memcpy(str, buf, size);
- str[size-1] = 0;
+ memcpy(str, buf, len);
+ str[len] = 0; /* len excludes the null */
free_memory(buf);
return len;
#endif
struct tm *localtime_r(const time_t *timep, struct tm *tm)
{
static pthread_mutex_t mutex;
- static int first = 1;
- struct tm *ltm;
+ static bool first = true;
+ struct tm *ltm,
if (first) {
pthread_mutex_init(&mutex, NULL);
- first = 0;
+ first = false;
}
+
P(mutex);
+
ltm = localtime(timep);
if (ltm) {
memcpy(tm, ltm, sizeof(struct tm));
struct stat statp;
Mmsg(&fname, "%s/%s.%d.pid", dir, progname, port);
- if (stat(mp_chr(fname), &statp) == 0) {
+ if (stat(fname, &statp) == 0) {
/* File exists, see what we have */
*pidbuf = 0;
- if ((pidfd = open(mp_chr(fname), O_RDONLY|O_BINARY, 0)) < 0 ||
+ if ((pidfd = open(fname, O_RDONLY|O_BINARY, 0)) < 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(mp_chr(fname)); /* remove stale pid file */
+ unlink(fname); /* remove stale pid file */
}
/* Create new pid file */
- if ((pidfd = open(mp_chr(fname), O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, 0640)) >= 0) {
+ if ((pidfd = open(fname, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, 0640)) >= 0) {
len = sprintf(pidbuf, "%d\n", (int)getpid());
write(pidfd, pidbuf, len);
close(pidfd);
}
del_pid_file_ok = FALSE;
Mmsg(&fname, "%s/%s.%d.pid", dir, progname, port);
- unlink(mp_chr(fname));
+ unlink(fname);
free_pool_memory(fname);
#endif
return 1;
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(mp_chr(fname), O_RDONLY|O_BINARY, 0)) < 0) {
+ if ((sfd = open(fname, O_RDONLY|O_BINARY, 0)) < 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 */
- if ((sfd = open(mp_chr(fname), O_CREAT|O_WRONLY|O_BINARY, 0640)) < 0) {
+ if ((sfd = open(fname, O_CREAT|O_WRONLY|O_BINARY, 0640)) < 0) {
Dmsg2(000, _("Could not create state file. %s ERR=%s\n"), fname, strerror(errno));
Emsg2(M_ERROR, 0, _("Could not create state file. %s ERR=%s\n"), fname, strerror(errno));
goto bail_out;
P(timer_mutex);
stat = pthread_cond_timedwait(&timer, &timer_mutex, &timeout);
if (stat != 0) {
+ berrno be;
Dmsg2(200, "pthread_cond_timedwait stat=%d ERR=%s\n", stat,
- strerror(stat));
+ be.strerror(stat));
}
V(timer_mutex);
return stat;