diff options
author | Jeremy Allison <jra@samba.org> | 2007-11-08 18:50:07 -0800 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2007-11-08 18:50:07 -0800 |
commit | 7a1de5b44e84a7474e78518c6ba33b3fedc42b5f (patch) | |
tree | b27891de35d06dc48adaa7d353ab3defe385a081 /source/lib/util.c | |
parent | c21bc756e36581d3adc770bc2b773b5cf9bf11d0 (diff) | |
download | samba-7a1de5b44e84a7474e78518c6ba33b3fedc42b5f.tar.gz samba-7a1de5b44e84a7474e78518c6ba33b3fedc42b5f.tar.xz samba-7a1de5b44e84a7474e78518c6ba33b3fedc42b5f.zip |
Remove more pstring/fstrings.
Jeremy.
Diffstat (limited to 'source/lib/util.c')
-rw-r--r-- | source/lib/util.c | 99 |
1 files changed, 43 insertions, 56 deletions
diff --git a/source/lib/util.c b/source/lib/util.c index ab33df47ee8..f96439525f0 100644 --- a/source/lib/util.c +++ b/source/lib/util.c @@ -1180,9 +1180,10 @@ void safe_free(void *p) Get my own name and IP. ****************************************************************************/ -bool get_myname(char *my_name) +char *get_myname(TALLOC_CTX *ctx) { - fstring hostname; + char *p; + char hostname[HOST_NAME_MAX]; *hostname = 0; @@ -1195,17 +1196,13 @@ bool get_myname(char *my_name) /* Ensure null termination. */ hostname[sizeof(hostname)-1] = '\0'; - if (my_name) { - /* split off any parts after an initial . */ - char *p = strchr_m(hostname,'.'); - - if (p) - *p = 0; - - fstrcpy(my_name,hostname); + /* split off any parts after an initial . */ + p = strchr_m(hostname,'.'); + if (p) { + *p = 0; } - return(True); + return talloc_strdup(ctx, hostname); } /**************************************************************************** @@ -2355,7 +2352,7 @@ char *smb_xstrndup(const char *s, size_t n) /***************************************************************** Like strdup but for memory. -*****************************************************************/ +*****************************************************************/ void *memdup(const void *p, size_t size) { @@ -2371,54 +2368,59 @@ void *memdup(const void *p, size_t size) /***************************************************************** Get local hostname and cache result. -*****************************************************************/ +*****************************************************************/ char *myhostname(void) { - static pstring ret; - if (ret[0] == 0) - get_myname(ret); + static char *ret; + if (ret == NULL) { + /* This is cached forever so + * use NULL talloc ctx. */ + ret = get_myname(NULL); + } return ret; } /***************************************************************** - A useful function for returning a path in the Samba lock directory. -*****************************************************************/ + A useful function for returning a path in the Samba pid directory. +*****************************************************************/ -char *lock_path(const char *name) +static char *xx_path(const char *name, const char *rootpath) { - pstring fname; + char *fname = NULL; - pstrcpy(fname,lp_lockdir()); - trim_char(fname,'\0','/'); - - if (!directory_exist(fname,NULL)) + fname = talloc_strdup(talloc_tos(), rootpath); + if (!fname) { + return NULL; + } + trim_string(fname,"","/"); + + if (!directory_exist(fname,NULL)) { mkdir(fname,0755); - - pstrcat(fname,"/"); - pstrcat(fname,name); + } - return talloc_strdup(talloc_tos(), fname); + return talloc_asprintf(talloc_tos(), + "%s/%s", + fname, + name); } /***************************************************************** - A useful function for returning a path in the Samba pid directory. + A useful function for returning a path in the Samba lock directory. *****************************************************************/ -char *pid_path(const char *name) +char *lock_path(const char *name) { - pstring fname; - - pstrcpy(fname,lp_piddir()); - trim_char(fname,'\0','/'); - - if (!directory_exist(fname,NULL)) - mkdir(fname,0755); + return xx_path(name, lp_lockdir()); +} - pstrcat(fname,"/"); - pstrcat(fname,name); +/***************************************************************** + A useful function for returning a path in the Samba pid directory. +*****************************************************************/ - return talloc_strdup(talloc_tos(), fname); +char *pid_path(const char *name) +{ + return xx_path(name, lp_piddir()); } /** @@ -2453,22 +2455,7 @@ a useful function for returning a path in the Samba state directory char *state_path(const char *name) { - TALLOC_CTX *ctx = talloc_tos(); - char *fname = talloc_strdup(ctx, dyn_STATEDIR()); - - if (!fname) { - smb_panic("state_path: out of memory"); - } - trim_string(fname,"","/"); - - if (!directory_exist(fname,NULL)) { - mkdir(fname,0755); - } - - fname = talloc_asprintf(ctx, "%s/%s", - fname, name); - - return fname; + return xx_path(name, dyn_STATEDIR()); } /** |