diff options
author | Volker Lendecke <vlendec@samba.org> | 2007-09-04 10:15:04 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:30:29 -0500 |
commit | ff0947fbed841065fce85c64ff4b2a2e8f24f056 (patch) | |
tree | df5c9cadb1d89cc0ee6b5fdf712743443b209d7c /source3/lib/util.c | |
parent | faefb22c61568c678476b4dad36bdc5ce3afb499 (diff) | |
download | samba-ff0947fbed841065fce85c64ff4b2a2e8f24f056.tar.gz samba-ff0947fbed841065fce85c64ff4b2a2e8f24f056.tar.bz2 samba-ff0947fbed841065fce85c64ff4b2a2e8f24f056.zip |
r24949: Remove some static buffers
(This used to be commit df648d47ff3c4e24f439fda839653bda98323100)
Diffstat (limited to 'source3/lib/util.c')
-rw-r--r-- | source3/lib/util.c | 76 |
1 files changed, 29 insertions, 47 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c index 3852fccdd1..5314239e07 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -456,7 +456,7 @@ SMB_OFF_T get_file_size(char *file_name) char *attrib_string(uint16 mode) { - static fstring attrstr; + fstring attrstr; attrstr[0] = 0; @@ -467,7 +467,7 @@ char *attrib_string(uint16 mode) if (mode & aSYSTEM) fstrcat(attrstr,"S"); if (mode & aRONLY) fstrcat(attrstr,"R"); - return(attrstr); + return talloc_strdup(talloc_tos(), attrstr); } /******************************************************************* @@ -1578,17 +1578,17 @@ BOOL process_exists_by_pid(pid_t pid) const char *uidtoname(uid_t uid) { - static fstring name; + fstring name; struct passwd *pass; - pass = getpwuid_alloc(NULL, uid); + pass = getpwuid_alloc(talloc_tos(), uid); if (pass) { fstrcpy(name, pass->pw_name); TALLOC_FREE(pass); } else { slprintf(name, sizeof(name) - 1, "%ld",(long int)uid); } - return name; + return talloc_strdup(talloc_tos(), name); } @@ -1598,14 +1598,17 @@ const char *uidtoname(uid_t uid) char *gidtoname(gid_t gid) { - static fstring name; + fstring name; struct group *grp; grp = getgrgid(gid); - if (grp) - return(grp->gr_name); - slprintf(name,sizeof(name) - 1, "%d",(int)gid); - return(name); + if (grp) { + fstrcpy(name, grp->gr_name); + } + else { + slprintf(name,sizeof(name) - 1, "%d",(int)gid); + } + return talloc_strdup(talloc_tos(), name); } /******************************************************************* @@ -1859,15 +1862,7 @@ const char *readdirname(SMB_STRUCT_DIR *p) dname = dname - 2; #endif - { - static pstring buf; - int len = NAMLEN(ptr); - memcpy(buf, dname, len); - buf[len] = 0; - dname = buf; - } - - return(dname); + return talloc_strdup(talloc_tos(), dname); } /******************************************************************* @@ -2629,7 +2624,7 @@ char *myhostname(void) char *lock_path(const char *name) { - static pstring fname; + pstring fname; pstrcpy(fname,lp_lockdir()); trim_char(fname,'\0','/'); @@ -2640,7 +2635,7 @@ char *lock_path(const char *name) pstrcat(fname,"/"); pstrcat(fname,name); - return fname; + return talloc_strdup(talloc_tos(), fname); } /***************************************************************** @@ -2649,7 +2644,7 @@ char *lock_path(const char *name) char *pid_path(const char *name) { - static pstring fname; + pstring fname; pstrcpy(fname,lp_piddir()); trim_char(fname,'\0','/'); @@ -2660,7 +2655,7 @@ char *pid_path(const char *name) pstrcat(fname,"/"); pstrcat(fname,name); - return fname; + return talloc_strdup(talloc_tos(), fname); } /** @@ -2673,9 +2668,7 @@ char *pid_path(const char *name) char *lib_path(const char *name) { - static pstring fname; - fstr_sprintf(fname, "%s/%s", dyn_LIBDIR, name); - return fname; + return talloc_asprintf(talloc_tos(), "%s/%s", dyn_LIBDIR, name); } /** @@ -2692,29 +2685,18 @@ const char *shlib_ext(void) /******************************************************************* Given a filename - get its directory name NB: Returned in static storage. Caveats: - o Not safe in thread environment. - o Caller must not free. o If caller wishes to preserve, they should copy. ********************************************************************/ char *parent_dirname(const char *path) { - static pstring dirpath; - char *p; - - if (!path) - return(NULL); + char *parent; - pstrcpy(dirpath, path); - p = strrchr_m(dirpath, '/'); /* Find final '/', if any */ - if (!p) { - pstrcpy(dirpath, "."); /* No final "/", so dir is "." */ - } else { - if (p == dirpath) - ++p; /* For root "/", leave "/" in place */ - *p = '\0'; + if (!parent_dirname_talloc(talloc_tos(), path, &parent, NULL)) { + return NULL; } - return dirpath; + + return parent; } BOOL parent_dirname_talloc(TALLOC_CTX *mem_ctx, const char *dir, @@ -3179,9 +3161,9 @@ struct server_id interpret_pid(const char *pid_string) #endif } -char *procid_str_static(const struct server_id *pid) +char *procid_str(TALLOC_CTX *mem_ctx, const struct server_id *pid) { - static fstring str; + fstring str; #ifdef CLUSTER_SUPPORT if (pid->vnn == NONCLUSTER_VNN) { fstr_sprintf(str, "%d", (int)pid->pid); @@ -3192,12 +3174,12 @@ char *procid_str_static(const struct server_id *pid) #else fstr_sprintf(str, "%d", (int)pid->pid); #endif - return str; + return talloc_strdup(mem_ctx, str); } -char *procid_str(TALLOC_CTX *mem_ctx, const struct server_id *pid) +char *procid_str_static(const struct server_id *pid) { - return talloc_strdup(mem_ctx, procid_str_static(pid)); + return procid_str(talloc_tos(), pid); } BOOL procid_valid(const struct server_id *pid) |