diff options
Diffstat (limited to 'source/lib/util.c')
-rw-r--r-- | source/lib/util.c | 186 |
1 files changed, 25 insertions, 161 deletions
diff --git a/source/lib/util.c b/source/lib/util.c index 921d683f4fb..9aad4f976aa 100644 --- a/source/lib/util.c +++ b/source/lib/util.c @@ -495,13 +495,13 @@ int set_blocking(int fd, BOOL set) #endif #endif - if((val = sys_fcntl_long(fd, F_GETFL, 0)) == -1) + if((val = fcntl(fd, F_GETFL, 0)) == -1) return -1; if(set) /* Turn blocking on - ie. clear nonblock flag */ val &= ~FLAG_TO_SET; else val |= FLAG_TO_SET; - return sys_fcntl_long( fd, F_SETFL, val); + return fcntl( fd, F_SETFL, val); #undef FLAG_TO_SET } @@ -563,16 +563,16 @@ ssize_t transfer_file_internal(int infd, int outfd, size_t n, ssize_t (*read_fn) SMB_OFF_T transfer_file(int infd,int outfd,SMB_OFF_T n) { - return (SMB_OFF_T)transfer_file_internal(infd, outfd, (size_t)n, sys_read, sys_write); + return (SMB_OFF_T)transfer_file_internal(infd, outfd, (size_t)n, read, write); } /******************************************************************* Sleep for a specified number of milliseconds. ********************************************************************/ -void msleep(unsigned int t) +void msleep(int t) { - unsigned int tdiff=0; + int tdiff=0; struct timeval tval,t1,t2; fd_set fds; @@ -582,23 +582,12 @@ void msleep(unsigned int t) while (tdiff < t) { tval.tv_sec = (t-tdiff)/1000; tval.tv_usec = 1000*((t-tdiff)%1000); - - /* Never wait for more than 1 sec. */ - if (tval.tv_sec > 1) { - tval.tv_sec = 1; - tval.tv_usec = 0; - } - + FD_ZERO(&fds); errno = 0; sys_select_intr(0,&fds,NULL,NULL,&tval); GetTimeOfDay(&t2); - if (t2.tv_sec < t1.tv_sec) { - /* Someone adjusted time... */ - t1 = t2; - } - tdiff = TvalDiff(&t1,&t2); } } @@ -804,32 +793,15 @@ struct in_addr *interpret_addr2(const char *str) } /******************************************************************* - Check if an IP is the 0.0.0.0 - ******************************************************************/ - -BOOL is_zero_ip(struct in_addr ip) + check if an IP is the 0.0.0.0 + ******************************************************************/ +BOOL zero_ip(struct in_addr ip) { - uint32 a; - putip((char *)&a,(char *)&ip); - return(a == 0); + uint32 a; + putip((char *)&a,(char *)&ip); + return(a == 0); } -/******************************************************************* - Set an IP to 0.0.0.0 - ******************************************************************/ - -void zero_ip(struct in_addr *ip) -{ - static BOOL init; - static struct in_addr ipzero; - - if (!init) { - ipzero = *interpret_addr2("0.0.0.0"); - init = True; - } - - *ip = ipzero; -} #if (defined(HAVE_NETGROUP) && defined(WITH_AUTOMOUNT)) /****************************************************************** @@ -1307,9 +1279,11 @@ BOOL fcntl_lock(int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type) lock.l_len = count; lock.l_pid = 0; - ret = sys_fcntl_ptr(fd,op,&lock); + errno = 0; - if (ret == -1 && errno != 0) + ret = fcntl(fd,op,&lock); + + if (errno != 0) DEBUG(3,("fcntl_lock: fcntl lock gave errno %d (%s)\n",errno,strerror(errno))); /* a lock query */ @@ -1359,25 +1333,6 @@ BOOL is_myname(char *s) return(ret); } -/******************************************************************** - Return only the first IP address of our configured interfaces - as a string - *******************************************************************/ - -const char* get_my_primary_ip (void) -{ - static fstring ip_string; - int n; - struct iface_struct nics[MAX_INTERFACES]; - - if ((n=get_interfaces(nics, MAX_INTERFACES)) <= 0) - return NULL; - - fstrcpy(ip_string, inet_ntoa(nics[0].ip)); - return ip_string; -} - - BOOL is_myname_or_ipaddr(char *s) { char *ptr; @@ -1755,10 +1710,11 @@ void *smb_xmalloc(size_t size) return p; } -/** +/***************************************************************** Memdup with smb_panic on fail. -**/ -void *smb_xmemdup(const void *p, size_t size) + *****************************************************************/ + +void *xmemdup(const void *p, size_t size) { void *p2; p2 = smb_xmalloc(size); @@ -1766,30 +1722,18 @@ void *smb_xmemdup(const void *p, size_t size) return p2; } -/** +/***************************************************************** strdup that aborts on malloc fail. -**/ -char *smb_xstrdup(const char *s) + *****************************************************************/ + +char *xstrdup(const char *s) { char *s1 = strdup(s); if (!s1) - smb_panic("smb_xstrdup: malloc fail\n"); + smb_panic("xstrdup: malloc fail\n"); return s1; } -/* - vasprintf that aborts on malloc fail -*/ -int smb_xvasprintf(char **ptr, const char *format, va_list ap) -{ - int n; - n = vasprintf(ptr, format, ap); - if (n == -1 || ! *ptr) { - smb_panic("smb_xvasprintf: out of memory"); - } - return n; -} - /***************************************************************** like strdup but for memory *****************************************************************/ @@ -2031,86 +1975,6 @@ BOOL unix_wild_match(char *pattern, char *string) return unix_do_match(p2, s2) == 0; } -/******************************************************************* - free() a data blob -*******************************************************************/ - -static void free_data_blob(DATA_BLOB *d) -{ - if ((d) && (d->free)) { - SAFE_FREE(d->data); - } -} - -/******************************************************************* - construct a data blob, must be freed with data_blob_free() - you can pass NULL for p and get a blank data blob -*******************************************************************/ - -DATA_BLOB data_blob(const void *p, size_t length) -{ - DATA_BLOB ret; - - if (!length) { - ZERO_STRUCT(ret); - return ret; - } - - if (p) { - ret.data = smb_xmemdup(p, length); - } else { - ret.data = smb_xmalloc(length); - } - ret.length = length; - ret.free = free_data_blob; - return ret; -} - -/******************************************************************* - construct a data blob, using supplied TALLOC_CTX -*******************************************************************/ - -DATA_BLOB data_blob_talloc(TALLOC_CTX *mem_ctx, const void *p, size_t length) -{ - DATA_BLOB ret; - - if (!p || !length) { - ZERO_STRUCT(ret); - return ret; - } - - ret.data = talloc_memdup(mem_ctx, p, length); - if (ret.data == NULL) - smb_panic("data_blob_talloc: talloc_memdup failed.\n"); - - ret.length = length; - ret.free = NULL; - return ret; -} - -/******************************************************************* -free a data blob -*******************************************************************/ -void data_blob_free(DATA_BLOB *d) -{ - if (d) { - if (d->free) { - (d->free)(d); - } - ZERO_STRUCTP(d); - } -} - -/******************************************************************* -clear a DATA_BLOB's contents -*******************************************************************/ -void data_blob_clear(DATA_BLOB *d) -{ - if (d->data) { - memset(d->data, 0, d->length); - } -} - #ifdef __INSURE__ /******************************************************************* |