-/*
+/*
Unix SMB/CIFS implementation.
replacement routines for broken systems
Copyright (C) Andrew Tridgell 1992-1998
** NOTE! The following LGPL license applies to the replace
** library. This does NOT imply that all of Samba is released
** under the LGPL
-
+
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
#endif
#ifndef HAVE_STRLCAT
-/* like strncat but does not 0 fill the buffer and always null
+/* like strncat but does not 0 fill the buffer and always null
terminates. bufsize is the length of the buffer, which should
be one more than the maximum resulting string length */
size_t rep_strlcat(char *d, const char *s, size_t bufsize)
#ifndef HAVE_MKTIME
/*******************************************************************
-a mktime() replacement for those who don't have it - contributed by
+a mktime() replacement for those who don't have it - contributed by
C.A. Lademann <cal@zls.com>
Corrections by richard.kettlewell@kewill.com
********************************************************************/
return((time_t)-1);
n = t->tm_year + 1900 - 1;
- epoch = (t->tm_year - 70) * YEAR +
+ epoch = (t->tm_year - 70) * YEAR +
((n / 4 - n / 100 + n / 400) - (1969 / 4 - 1969 / 100 + 1969 / 400)) * DAY;
y = t->tm_year + 1900;
epoch += mon [m] * DAY;
if(m == 1 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0))
epoch += DAY;
-
+
if(++m > 11) {
m = 0;
y++;
epoch += (t->tm_mday - 1) * DAY;
epoch += t->tm_hour * HOUR + t->tm_min * MINUTE + t->tm_sec;
-
+
if((u = localtime(&epoch)) != NULL) {
t->tm_sec = u->tm_sec;
t->tm_min = u->tm_min;
#ifndef HAVE_INITGROUPS
/****************************************************************************
- some systems don't have an initgroups call
+ some systems don't have an initgroups call
****************************************************************************/
int rep_initgroups(char *name, gid_t id)
{
int i,j;
struct group *g;
char *gr;
-
+
if((grouplst = malloc(sizeof(gid_t) * max_gr)) == NULL) {
errno = ENOMEM;
return -1;
if (d < s) {
/* we can forward copy */
- if (s-d >= sizeof(int) &&
- !(s%sizeof(int)) &&
- !(d%sizeof(int)) &&
+ if (s-d >= sizeof(int) &&
+ !(s%sizeof(int)) &&
+ !(d%sizeof(int)) &&
!(size%sizeof(int))) {
/* do it all as words */
int *idest = (int *)dest;
}
} else {
/* must backward copy */
- if (d-s >= sizeof(int) &&
- !(s%sizeof(int)) &&
- !(d%sizeof(int)) &&
+ if (d-s >= sizeof(int) &&
+ !(s%sizeof(int)) &&
+ !(d%sizeof(int)) &&
!(size%sizeof(int))) {
/* do it all as words */
int *idest = (int *)dest;
char *cdest = (char *)dest;
char *csrc = (char *)src;
for (i=size-1;i>=0;i--) cdest[i] = csrc[i];
- }
+ }
}
return(dest);
}
size_t rep_strnlen(const char *s, size_t max)
{
size_t len;
-
+
for (len = 0; len < max; len++) {
if (s[len] == '\0') {
break;
}
}
- return len;
+ return len;
}
#endif
-
+
#ifndef HAVE_STRNDUP
/**
Some platforms don't have strndup.
char *rep_strndup(const char *s, size_t n)
{
char *ret;
-
+
n = strnlen(s, n);
ret = malloc(n+1);
if (!ret)
/*****************************************************************
Possibly replace mkstemp if it is broken.
-*****************************************************************/
+*****************************************************************/
#ifndef HAVE_SECURE_MKSTEMP
int rep_mkstemp(char *template)
char *rep_mkdtemp(char *template)
{
char *dname;
-
+
if ((dname = mktemp(template))) {
if (mkdir(dname, 0700) >= 0) {
return dname;
{
#ifdef HAVE_STRTOQ
return strtoq(str, endptr, base);
-#elif defined(HAVE___STRTOLL)
+#elif defined(HAVE___STRTOLL)
return __strtoll(str, endptr, base);
#elif SIZEOF_LONG == SIZEOF_LONG_LONG
return (long long int) strtol(str, endptr, base);
{
#ifdef HAVE_STRTOUQ
return strtouq(str, endptr, base);
-#elif defined(HAVE___STRTOULL)
+#elif defined(HAVE___STRTOULL)
return __strtoull(str, endptr, base);
#elif SIZEOF_LONG == SIZEOF_LONG_LONG
return (unsigned long long int) strtoul(str, endptr, base);
#endif /* HAVE_STRTOULL */
#ifndef HAVE_SETENV
-int rep_setenv(const char *name, const char *value, int overwrite)
+int rep_setenv(const char *name, const char *value, int overwrite)
{
char *p;
size_t l1, l2;
for (i=0;environ[i];i++) /* noop */ ;
count=i;
-
+
for (i=0;i<count;) {
if (strncmp(environ[i], name, len) == 0 && environ[i][len] == '=') {
- /* note: we do _not_ free the old variable here. It is unsafe to
+ /* note: we do _not_ free the old variable here. It is unsafe to
do so, as the pointer may not have come from malloc */
memmove(&environ[i], &environ[i+1], (count-i)*sizeof(char *));
count--;
#endif
#ifndef HAVE_DUP2
-int rep_dup2(int oldfd, int newfd)
+int rep_dup2(int oldfd, int newfd)
{
errno = ENOSYS;
return -1;