summaryrefslogtreecommitdiff
path: root/lib/util
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2009-02-13 10:56:34 +0100
committerVolker Lendecke <vl@samba.org>2009-02-13 12:15:03 +0100
commit0844cca1d5e4579b54af7d03509f3f97fac43bdc (patch)
tree48e92ab9ebeb54a485394849e3bcc2b0aca7734a /lib/util
parente7f7ed8bf6281ef01aca53ea44acdd4af4c51aa7 (diff)
downloadsamba-0844cca1d5e4579b54af7d03509f3f97fac43bdc.tar.gz
samba-0844cca1d5e4579b54af7d03509f3f97fac43bdc.tar.bz2
samba-0844cca1d5e4579b54af7d03509f3f97fac43bdc.zip
Replace get_myname() with the talloc version from v3-3-test
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/util.c26
-rw-r--r--lib/util/util.h4
2 files changed, 13 insertions, 17 deletions
diff --git a/lib/util/util.c b/lib/util/util.c
index 40ac7f79e6..988d8f9fa0 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -192,34 +192,30 @@ _PUBLIC_ void msleep(unsigned int t)
}
/**
- Get my own name, return in malloc'ed storage.
+ Get my own name, return in talloc'ed storage.
**/
-_PUBLIC_ char *get_myname(void)
+_PUBLIC_ char *get_myname(TALLOC_CTX *ctx)
{
- char *hostname;
char *p;
-
- hostname = (char *)malloc(MAXHOSTNAMELEN+1);
- *hostname = 0;
+ char hostname[HOST_NAME_MAX];
/* get my host name */
- if (gethostname(hostname, MAXHOSTNAMELEN+1) == -1) {
+ if (gethostname(hostname, sizeof(hostname)) == -1) {
DEBUG(0,("gethostname failed\n"));
- free(hostname);
return NULL;
- }
+ }
/* Ensure null termination. */
- hostname[MAXHOSTNAMELEN] = '\0';
+ hostname[sizeof(hostname)-1] = '\0';
/* split off any parts after an initial . */
- p = strchr(hostname, '.');
-
- if (p != NULL)
+ p = strchr_m(hostname, '.');
+ if (p) {
*p = 0;
-
- return hostname;
+ }
+
+ return talloc_strdup(ctx, hostname);
}
/**
diff --git a/lib/util/util.h b/lib/util/util.h
index dced557acb..7873f0e769 100644
--- a/lib/util/util.h
+++ b/lib/util/util.h
@@ -536,9 +536,9 @@ _PUBLIC_ int set_blocking(int fd, bool set);
_PUBLIC_ void msleep(unsigned int t);
/**
- Get my own name, return in malloc'ed storage.
+ Get my own name, return in talloc'ed storage.
**/
-_PUBLIC_ char* get_myname(void);
+_PUBLIC_ char* get_myname(TALLOC_CTX *mem_ctx);
/**
Return true if a string could be a pure IP address.