Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!decwrl!ucbvax!MAILGW.CC.UMICH.EDU!rees From: rees@MAILGW.CC.UMICH.EDU (Jim Rees) Newsgroups: comp.sys.apollo Subject: Re: gethostname (was: gpr_$borrow mode and ^q) Message-ID: <8809151702.AA00749@mailgw.cc.umich.edu> Date: 15 Sep 88 17:07:43 GMT References: Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: rees@caen.engin.umich.edu (Jim Rees) Organization: The Internet Lines: 36 > my program also needs to write to a file in /tmp. i need the >full absolute pathname of this file right from the network root //. >so i use the unix system call, gethostname(host, strlen(host)). >but this returns -1 and *host == NULL. i fixed this by using name_$get_path(). suppose my filename is in buf: char bar[256]; sprintf(bar, "/tmp/lock-%s", pp->pw_name); then the following char foo[256]; short len; name_$get_path(bar, (short)strlen(bar), foo, len, status); printf("%sn", foo); will produce //wm/sys/node_data/tmp/lock-fclim (the output is actually in upper case; i'm too lazy here to shift.) since we have crl /tmp `node_data/tmp on node //wm. Here's how to do it case-correct: #include "/sys/ins/base.ins.c" #include "/sys/ins/name.ins.c" main() { name_$long_pname_t name; short namelen; status_$t st; name_$get_path_lc("/", 1, (short) sizeof name, name, namelen, st); name[namelen] = '\0'; printf("%s\n", name); } -------