summaryrefslogtreecommitdiff
path: root/nis/nis_local_names.c
diff options
context:
space:
mode:
Diffstat (limited to 'nis/nis_local_names.c')
-rw-r--r--nis/nis_local_names.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/nis/nis_local_names.c b/nis/nis_local_names.c
index 50120a6f73..e760f433b2 100644
--- a/nis/nis_local_names.c
+++ b/nis/nis_local_names.c
@@ -158,26 +158,29 @@ nis_local_host (void)
if (__nishostname[0] == '\0')
{
- char *cp = __nishostname;
-
if (gethostname (__nishostname, NIS_MAXNAMELEN) < 0)
- cp = stpcpy (cp, "\0");
+ __nishostname[0] = '\0';
+ else
+ {
+ char *cp;
+ len = strlen(__nishostname);
- len = cp - __nishostname;
+ /* Hostname already fully qualified? */
+ if (__nishostname[len - 1] == '.')
+ return __nishostname;
- /* Hostname already fully qualified? */
- if (__nishostname[len - 1] == '.')
- return __nishostname;
+ if ((strlen (__nishostname) + strlen (nis_local_directory ()) + 1) >
+ NIS_MAXNAMELEN)
+ {
+ __nishostname[0] = '\0';
+ return __nishostname;
+ }
- if (strlen (__nishostname + strlen (nis_local_directory ()) + 1) >
- NIS_MAXNAMELEN)
- {
- __nishostname[0] = '\0';
- return __nishostname;
+ cp = &__nishostname[len];
+ *cp++ = '.';
+ strncpy (cp, nis_local_directory (), NIS_MAXNAMELEN - len -1);
+ __nishostname[NIS_MAXNAMELEN] = '\0';
}
-
- *cp++ = '.';
- stpcpy (cp, nis_local_directory ());
}
return __nishostname;