diff options
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/charset.c | 2 | ||||
-rw-r--r-- | source3/lib/debug.c | 8 | ||||
-rw-r--r-- | source3/lib/genrand.c | 4 | ||||
-rw-r--r-- | source3/lib/kanji.c | 14 | ||||
-rw-r--r-- | source3/lib/pidfile.c | 4 | ||||
-rw-r--r-- | source3/lib/smbrun.c | 2 | ||||
-rw-r--r-- | source3/lib/system.c | 62 | ||||
-rw-r--r-- | source3/lib/username.c | 2 | ||||
-rw-r--r-- | source3/lib/util.c | 6 | ||||
-rw-r--r-- | source3/lib/util_file.c | 2 | ||||
-rw-r--r-- | source3/lib/util_str.c | 70 |
11 files changed, 116 insertions, 60 deletions
diff --git a/source3/lib/charset.c b/source3/lib/charset.c index 5bf3bfbe30..fc2924a155 100644 --- a/source3/lib/charset.c +++ b/source3/lib/charset.c @@ -235,7 +235,7 @@ code page file (size=%d).\n", codepage_file_name, (int)size)); is held in little endian format. */ - if((fp = fopen( codepage_file_name, "r")) == NULL) + if((fp = sys_fopen( codepage_file_name, "r")) == NULL) { DEBUG(0,("load_client_codepage: cannot open file %s. Error was %s\n", codepage_file_name, strerror(errno))); diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 619a917747..3a90da2f3d 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -224,9 +224,9 @@ void reopen_logs( void ) if( dbf ) (void)fclose( dbf ); if( append_log ) - dbf = fopen( debugf, "a" ); + dbf = sys_fopen( debugf, "a" ); else - dbf = fopen( debugf, "w" ); + dbf = sys_fopen( debugf, "w" ); /* Fix from klausr@ITAP.Physik.Uni-Stuttgart.De * to fix problem where smbd's that generate less * than 100 messages keep growing the log. @@ -331,9 +331,9 @@ va_dcl mode_t oldumask = umask( 022 ); if( append_log ) - dbf = fopen( debugf, "a" ); + dbf = sys_fopen( debugf, "a" ); else - dbf = fopen( debugf, "w" ); + dbf = sys_fopen( debugf, "w" ); (void)umask( oldumask ); if( dbf ) { diff --git a/source3/lib/genrand.c b/source3/lib/genrand.c index bb1922e4f5..8b05b02f94 100644 --- a/source3/lib/genrand.c +++ b/source3/lib/genrand.c @@ -36,7 +36,7 @@ static void do_filehash(char *fname, unsigned char *hash) unsigned char tmp_md4[16]; int fd, n; - fd = open(fname,O_RDONLY); + fd = sys_open(fname,O_RDONLY,0); if (fd == -1) return; while ((n = read(fd, (char *)buf, sizeof(buf))) > 0) { @@ -121,7 +121,7 @@ static uint32 do_reseed(unsigned char *md4_outbuf) memset(md4_inbuf, '\0', sizeof(md4_inbuf)); - fd = open( "/dev/random", O_RDONLY); + fd = sys_open( "/dev/random", O_RDONLY,0); if(fd >= 0) { /* * We can use /dev/random ! diff --git a/source3/lib/kanji.c b/source3/lib/kanji.c index 565e8d852f..871a4a059c 100644 --- a/source3/lib/kanji.c +++ b/source3/lib/kanji.c @@ -54,12 +54,12 @@ char *(*multibyte_strtok)(char *, const char *) = (char *(*)(char *, const char * charcnv.c. */ -static int skip_non_multibyte_char(char); +static size_t skip_non_multibyte_char(char); static BOOL not_multibyte_char_1(char); char *(*_dos_to_unix)(char *, BOOL) = dos2unix_format; char *(*_unix_to_dos)(char *, BOOL) = unix2dos_format; -int (*_skip_multibyte_char)(char) = skip_non_multibyte_char; +size_t (*_skip_multibyte_char)(char) = skip_non_multibyte_char; BOOL (*is_multibyte_char_1)(char) = not_multibyte_char_1; #else /* KANJI */ @@ -70,12 +70,12 @@ BOOL (*is_multibyte_char_1)(char) = not_multibyte_char_1; */ static char *sj_to_sj(char *from, BOOL overwrite); -static int skip_kanji_multibyte_char(char); +static size_t skip_kanji_multibyte_char(char); static BOOL is_kanji_multibyte_char_1(char); char *(*_dos_to_unix)(char *, BOOL) = sj_to_sj; char *(*_unix_to_dos)(char *, BOOL) = sj_to_sj; -int (*_skip_multibyte_char)(char) = skip_kanji_multibyte_char; +size_t (*_skip_multibyte_char)(char) = skip_kanji_multibyte_char; int (*is_multibyte_char_1)(char) = is_kanji_multibyte_char_1; #endif /* KANJI */ @@ -198,7 +198,7 @@ static const char *sj_strrchr(const char *s, int c) Kanji multibyte char skip function. *******************************************************************/ -static int skip_kanji_multibyte_char(char c) +static size_t skip_kanji_multibyte_char(char c) { if(is_shift_jis(c)) { return 2; @@ -364,7 +364,7 @@ static const char *generic_multibyte_strrchr(const char *s, int c) Generic multibyte char skip function. *******************************************************************/ -static int skip_generic_multibyte_char(char c) +static size_t skip_generic_multibyte_char(char c) { if( (*is_multibyte_char_1)(c)) { return 2; @@ -1143,7 +1143,7 @@ void interpret_coding_system(char *str) Non multibyte char function. *******************************************************************/ -static int skip_non_multibyte_char(char c) +static size_t skip_non_multibyte_char(char c) { return 0; } diff --git a/source3/lib/pidfile.c b/source3/lib/pidfile.c index 7e98438dba..52a3be875f 100644 --- a/source3/lib/pidfile.c +++ b/source3/lib/pidfile.c @@ -38,7 +38,7 @@ pid_t pidfile_pid(char *name) slprintf(pidFile, sizeof(pidFile)-1, "%s/%s.pid", lp_lockdir(), name); - f = fopen(pidFile, "r"); + f = sys_fopen(pidFile, "r"); if (!f) { return 0; } @@ -71,7 +71,7 @@ void pidfile_create(char *name) exit(1); } - fd = open(pidFile, O_NONBLOCK | O_CREAT | O_WRONLY, 0644); + fd = sys_open(pidFile, O_NONBLOCK | O_CREAT | O_WRONLY, 0644); if (fd < 0) { DEBUG(0,("ERROR: can't open %s: Error was %s\n", pidFile, strerror(errno))); diff --git a/source3/lib/smbrun.c b/source3/lib/smbrun.c index 86d7cf9e03..da7632a67a 100644 --- a/source3/lib/smbrun.c +++ b/source3/lib/smbrun.c @@ -58,7 +58,7 @@ static BOOL setup_stdout_file(char *outfile,BOOL shared) flags = O_RDWR; } /* now create the file */ - fd = open(outfile,flags,mode); + fd = sys_open(outfile,flags,mode); if (fd == -1) return False; diff --git a/source3/lib/system.c b/source3/lib/system.c index deca7e1b6a..d07df3faf0 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -231,6 +231,62 @@ SMB_OFF_T sys_ftell(FILE *fp) } /******************************************************************* + A creat() wrapper that will deal with 64 bit filesizes. +********************************************************************/ + +int sys_creat(const char *path, mode_t mode) +{ +#if defined(HAVE_CREAT64) + return creat64(path, mode); +#else + /* + * If creat64 isn't defined then ensure we call a potential open64. + * JRA. + */ + return sys_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode); +#endif +} + +/******************************************************************* + An open() wrapper that will deal with 64 bit filesizes. +********************************************************************/ + +int sys_open(const char *path, int oflag, mode_t mode) +{ +#if defined(HAVE_OPEN64) + return open64(path, oflag, mode); +#else + return open(path, oflag, mode); +#endif +} + +/******************************************************************* + An fopen() wrapper that will deal with 64 bit filesizes. +********************************************************************/ + +FILE *sys_fopen(const char *path, const char *type) +{ +#if defined(HAVE_FOPEN64) + return fopen64(path, type); +#else + return fopen(path, type); +#endif +} + +/******************************************************************* + An mmap() wrapper that will deal with 64 bit filesizes. +********************************************************************/ + +void *sys_mmap(void *addr, size_t len, int prot, int flags, int fd, SMB_OFF_T offset) +{ +#if defined(LARGE_SMB_OFF_T) && defined(HAVE_MMAP64) + return mmap64(addr, len, prot, flags, fd, offset); +#else + return mmap(addr, len, prot, flags, fd, offset); +#endif +} + +/******************************************************************* just a unlink wrapper that calls dos_to_unix. ********************************************************************/ int dos_unlink(char *fname) @@ -244,7 +300,7 @@ a simple open() wrapper that calls dos_to_unix. ********************************************************************/ int dos_open(char *fname,int flags,mode_t mode) { - return(open(dos_to_unix(fname,False),flags,mode)); + return(sys_open(dos_to_unix(fname,False),flags,mode)); } @@ -345,10 +401,10 @@ static int copy_reg(char *source, const char *dest) if (unlink (dest) && errno != ENOENT) return 1; - if((ifd = open (source, O_RDONLY, 0)) < 0) + if((ifd = sys_open (source, O_RDONLY, 0)) < 0) return 1; - if((ofd = open (dest, O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0 ) + if((ofd = sys_open (dest, O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0 ) { close (ifd); return 1; diff --git a/source3/lib/username.c b/source3/lib/username.c index f56f7efce2..f04314ab36 100644 --- a/source3/lib/username.c +++ b/source3/lib/username.c @@ -80,7 +80,7 @@ BOOL map_username(char *user) return True; } - f = fopen(mapfile,"r"); + f = sys_fopen(mapfile,"r"); if (!f) { DEBUG(0,("can't open username map %s\n",mapfile)); return False; diff --git a/source3/lib/util.c b/source3/lib/util.c index df3faa569a..7247e95c64 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1059,8 +1059,8 @@ void close_low_fds(void) /* try and use up these file descriptors, so silly library routines writing to stdout etc won't cause havoc */ for (i=0;i<3;i++) { - fd = open("/dev/null",O_RDWR,0); - if (fd < 0) fd = open("/dev/null",O_WRONLY,0); + fd = sys_open("/dev/null",O_RDWR,0); + if (fd < 0) fd = sys_open("/dev/null",O_WRONLY,0); if (fd < 0) { DEBUG(0,("Can't open /dev/null\n")); return; @@ -1705,7 +1705,7 @@ void become_daemon(void) setsid(); #elif defined(TIOCNOTTY) { - int i = open("/dev/tty", O_RDWR); + int i = sys_open("/dev/tty", O_RDWR, 0); if (i != -1) { ioctl(i, (int) TIOCNOTTY, (char *)0); close(i); diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c index 0d6e77b010..faceed1dbd 100644 --- a/source3/lib/util_file.c +++ b/source3/lib/util_file.c @@ -125,7 +125,7 @@ void *startfilepwent(char *pfile, char *s_readbuf, int bufsize, } DEBUG(10, ("startfilepwent: opening file %s\n", pfile)); - fp = fopen(pfile, update ? "r+b" : "rb"); + fp = sys_fopen(pfile, update ? "r+b" : "rb"); if (fp == NULL) { DEBUG(0, ("startfilepwent: unable to open file %s\n", pfile)); diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 02fa892d7b..c943a854cf 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -36,11 +36,11 @@ void set_first_token(char *ptr) Based on a routine by GJC@VILLAGE.COM. Extensively modified by Andrew.Tridgell@anu.edu.au ****************************************************************************/ -BOOL next_token(char **ptr,char *buff,char *sep, int bufsize) +BOOL next_token(char **ptr,char *buff,char *sep, size_t bufsize) { char *s; BOOL quoted; - int len=1; + size_t len=1; if (!ptr) ptr = &last_ptr; if (!ptr) return(False); @@ -188,7 +188,7 @@ int StrCaseCmp(const char *s, const char *t) /******************************************************************* case insensitive string compararison, length limited ********************************************************************/ -int StrnCaseCmp(char *s, char *t, int n) +int StrnCaseCmp(const char *s, const char *t, size_t n) { /* compare until we run out of string, either t or s, or chars */ /* We *must* use toupper rather than tolower here due to the @@ -283,7 +283,7 @@ BOOL strequal(const char *s1, const char *s2) /******************************************************************* compare 2 strings up to and including the nth char. ******************************************************************/ -BOOL strnequal(char *s1,char *s2,int n) +BOOL strnequal(const char *s1,const char *s2,size_t n) { if (s1 == s2) return(True); if (!s1 || !s2 || !n) return(False); @@ -294,7 +294,7 @@ BOOL strnequal(char *s1,char *s2,int n) /******************************************************************* compare 2 strings (case sensitive) ********************************************************************/ -BOOL strcsequal(char *s1,char *s2) +BOOL strcsequal(const char *s1,const char *s2) { if (s1 == s2) return(True); if (!s1 || !s2) return(False); @@ -343,7 +343,7 @@ void strlower(char *s) else #endif /* KANJI_WIN95_COMPATIBILITY */ { - int skip = skip_multibyte_char( *s ); + size_t skip = skip_multibyte_char( *s ); if( skip != 0 ) s += skip; else @@ -396,7 +396,7 @@ void strupper(char *s) else #endif /* KANJI_WIN95_COMPATIBILITY */ { - int skip = skip_multibyte_char( *s ); + size_t skip = skip_multibyte_char( *s ); if( skip != 0 ) s += skip; else @@ -439,7 +439,7 @@ BOOL strisnormal(char *s) ****************************************************************************/ void string_replace(char *s,char oldc,char newc) { - int skip; + size_t skip; while (*s) { skip = skip_multibyte_char( *s ); @@ -458,11 +458,11 @@ void string_replace(char *s,char oldc,char newc) /******************************************************************* skip past some strings in a buffer ********************************************************************/ -char *skip_string(char *buf,int n) +char *skip_string(const char *buf,size_t n) { while (n--) buf += strlen(buf) + 1; - return(buf); + return((char *)buf); } /******************************************************************* @@ -472,7 +472,7 @@ char *skip_string(char *buf,int n) 16.oct.98, jdblair@cobaltnet.com. ********************************************************************/ -size_t str_charnum(char *s) +size_t str_charnum(const char *s) { size_t len = 0; @@ -488,7 +488,7 @@ size_t str_charnum(char *s) trim the specified elements off the front and back of a string ********************************************************************/ -BOOL trim_string(char *s,char *front,char *back) +BOOL trim_string(char *s,const char *front,const char *back) { BOOL ret = False; size_t front_len = (front && *front) ? strlen(front) : 0; @@ -584,7 +584,7 @@ BOOL trim_string(char *s,char *front,char *back) /**************************************************************************** does a string have any uppercase chars in it? ****************************************************************************/ -BOOL strhasupper(char *s) +BOOL strhasupper(const char *s) { while (*s) { @@ -615,7 +615,7 @@ BOOL strhasupper(char *s) else #endif /* KANJI_WIN95_COMPATIBILITY */ { - int skip = skip_multibyte_char( *s ); + size_t skip = skip_multibyte_char( *s ); if( skip != 0 ) s += skip; else { @@ -631,7 +631,7 @@ BOOL strhasupper(char *s) /**************************************************************************** does a string have any lowercase chars in it? ****************************************************************************/ -BOOL strhaslower(char *s) +BOOL strhaslower(const char *s) { while (*s) { @@ -670,7 +670,7 @@ BOOL strhaslower(char *s) else #endif /* KANJI_WIN95_COMPATIBILITY */ { - int skip = skip_multibyte_char( *s ); + size_t skip = skip_multibyte_char( *s ); if( skip != 0 ) s += skip; else { @@ -686,9 +686,9 @@ BOOL strhaslower(char *s) /**************************************************************************** find the number of chars in a string ****************************************************************************/ -int count_chars(char *s,char c) +size_t count_chars(const char *s,char c) { - int count=0; + size_t count=0; #if !defined(KANJI_WIN95_COMPATIBILITY) /* @@ -720,7 +720,7 @@ int count_chars(char *s,char c) { while (*s) { - int skip = skip_multibyte_char( *s ); + size_t skip = skip_multibyte_char( *s ); if( skip != 0 ) s += skip; else { @@ -739,9 +739,9 @@ int count_chars(char *s,char c) safe string copy into a known length string. maxlength does not include the terminating zero. ********************************************************************/ -char *safe_strcpy(char *dest,const char *src, int maxlength) +char *safe_strcpy(char *dest,const char *src, size_t maxlength) { - int len; + size_t len; if (!dest) { DEBUG(0,("ERROR: NULL dest in safe_strcpy\n")); @@ -770,9 +770,9 @@ char *safe_strcpy(char *dest,const char *src, int maxlength) safe string cat into a string. maxlength does not include the terminating zero. ********************************************************************/ -char *safe_strcat(char *dest, char *src, int maxlength) +char *safe_strcat(char *dest, const char *src, size_t maxlength) { - int src_len, dest_len; + size_t src_len, dest_len; if (!dest) { DEBUG(0,("ERROR: NULL dest in safe_strcat\n")); @@ -800,7 +800,7 @@ char *safe_strcat(char *dest, char *src, int maxlength) /**************************************************************************** this is a safer strcpy(), meant to prevent core dumps when nasty things happen ****************************************************************************/ -char *StrCpy(char *dest,char *src) +char *StrCpy(char *dest,const char *src) { char *d = dest; @@ -819,7 +819,7 @@ char *StrCpy(char *dest,char *src) /**************************************************************************** like strncpy but always null terminates. Make sure there is room! ****************************************************************************/ -char *StrnCpy(char *dest,const char *src,int n) +char *StrnCpy(char *dest,const char *src,size_t n) { char *d = dest; if (!dest) return(NULL); @@ -837,10 +837,10 @@ char *StrnCpy(char *dest,const char *src,int n) like strncpy but copies up to the character marker. always null terminates. returns a pointer to the character marker in the source string (src). ****************************************************************************/ -char *strncpyn(char *dest, const char *src,int n, char c) +char *strncpyn(char *dest, const char *src,size_t n, char c) { char *p; - int str_len; + size_t str_len; p = strchr(src, c); if (p == NULL) @@ -866,10 +866,10 @@ char *strncpyn(char *dest, const char *src,int n, char c) valid examples: "0A5D15"; "0x15, 0x49, 0xa2"; "59\ta9\te3\n" **************************************************************/ -int strhex_to_str(char *p, int len, const char *strhex) +size_t strhex_to_str(char *p, size_t len, const char *strhex) { - int i; - int num_chars = 0; + size_t i; + size_t num_chars = 0; unsigned char lonybble, hinybble; char *hexchars = "0123456789ABCDEF"; char *p1 = NULL, *p2 = NULL; @@ -935,9 +935,9 @@ static char *null_string = NULL; /**************************************************************************** set a string value, allocing the space for the string ****************************************************************************/ -BOOL string_init(char **dest,char *src) +BOOL string_init(char **dest,const char *src) { - int l; + size_t l; if (!src) src = ""; @@ -983,7 +983,7 @@ void string_free(char **s) set a string value, allocing the space for the string, and deallocating any existing space ****************************************************************************/ -BOOL string_set(char **dest,char *src) +BOOL string_set(char **dest,const char *src) { string_free(dest); @@ -999,11 +999,11 @@ insert. It may do multiple replacements. return True if a substitution was done. ****************************************************************************/ -BOOL string_sub(char *s,char *pattern,char *insert) +BOOL string_sub(char *s,const char *pattern,const char *insert) { BOOL ret = False; char *p; - int ls,lp,li; + size_t ls,lp,li; if (!insert || !pattern || !s) return(False); |