Changeset f54b07d for global.c


Ignore:
Timestamp:
Feb 26, 2011, 8:10:30 PM (13 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.8, release-1.9
Children:
9620c8d
Parents:
cb6c9e1
git-author:
David Benjamin <davidben@mit.edu> (01/04/11 11:15:08)
git-committer:
David Benjamin <davidben@mit.edu> (02/26/11 20:10:30)
Message:
Use g_get_host_name instead of gethostname and MAXHOSTNAMELEN

This lets us punt thishost from owl_global. g_get_host_name implements
the same localhost fallback, so we really don't need it.

Also, Solaris gets upset about MAXHOSTNAMELEN when you define
_XOPEN_SOURCE=500 without __EXTENSIONS__, if we ever care to get rid of
that. (That said, glib's answer to this is lame. They just hardcode 100
and even forget to NUL-terminate the buffer; POSIX is apparently
braindead and leaves truncation undefined. glibc is kind enough to give
you ENAMETOOLONG.)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • global.c

    r3472845 rf54b07d  
    99#include "owl.h"
    1010
    11 #ifndef MAXHOSTNAMELEN
    12 #define MAXHOSTNAMELEN 256
    13 #endif
    14 
    1511static void _owl_global_init_windows(owl_global *g);
    1612
    1713void owl_global_init(owl_global *g) {
    18   struct hostent *hent;
    19   char hostname[MAXHOSTNAMELEN];
    2014  char *cd;
    2115  const char *homedir;
    2216
    2317  g_type_init();
    24 
    25   gethostname(hostname, MAXHOSTNAMELEN);
    26   hent=gethostbyname(hostname);
    27   if (!hent) {
    28     g->thishost=g_strdup("localhost");
    29   } else {
    30     g->thishost=g_strdup(hent->h_name);
    31   }
    3218
    3319  g->lines=LINES;
     
    497483time_t owl_global_get_idletime(const owl_global *g) {
    498484  return(time(NULL)-g->lastinputtime);
    499 }
    500 
    501 const char *owl_global_get_hostname(const owl_global *g) {
    502   if (g->thishost) return(g->thishost);
    503   return("");
    504485}
    505486
Note: See TracChangeset for help on using the changeset viewer.