Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wasatch!cs.utexas.edu!uunet!mcvax!ukc!acorn!john From: john@acorn.co.uk (John Bowler) Newsgroups: comp.windows.x Subject: Re: Linking Libraries/Undefined variables Message-ID: <827@acorn.co.uk> Date: 18 Aug 89 13:49:10 GMT References: <3930009@hpcll01.HP.COM> <13489@bloom-beacon.MIT.EDU> <1687@bacchus.dec.com> Reply-To: john@acorn.UUCP (John Bowler) Organization: Acorn Computers Ltd, Cambridge, UK Lines: 66 In article <1687@bacchus.dec.com> klee@gilroy.pa.dec.com (Ken Lee) writes: >In article <3930009@hpcll01.HP.COM>, pratap@hpcll01.HP.COM (Pratap Subrahmanyam) writes: >> You are correct. Tempnam/Tmpnam is a routine in HP-UX C library that lets >> you create temporary files. ... > > [comment that DEC Ultrix includes both tempnam and tmpnam] tempnam is the System V interface, defined in both the SVID and the POSIX P1003 stuff. The current POSIX definition says (approximately):- char *tempnam(char *dir, char *pfx) generates a pathname that may be used for a temporary file. The dir argument points to the name of the directory in which the file is to be created. If dir is NULL or points to a string which is not the name of an appropriate directory the P_tmpdir path prefix from is used. The pfx argument may be NULL or point to a string of up to file characters to be used as the first few characters of the filename. Raw BSD systems do not contain this function. SUNOS systems contain System V compatibility libraries which have an appropriate definition. Aegis (Apollo) systems used to have both BSD and SysV support, so shouldn't cause problems either. The following code fragment might be sufficient (caveat emptor - in particular the SVID is more definitive about the behaviour if the relevant directories do not exist, this code assumes the caller has given an accessible directory). John Bowler (jbowler@acorn.co.uk) -------------------- cut here ----------------------------------- extern char *mktemp(/*-char *template-*/); /* BSD routine */ char *tempnam(dir, pfx) char *dir, *pfx; { int len, lend; char *result, *rtemp; if (!dir) dir = "/tmp"; /* Should be P_tmpdir... */ if (!pfx) pfx = "zz"; /* or anything with no X's in it */ lend = strlen(dir); if (dir[lend-1] != '/') ++lend; len = strlen(pfx); result = (char *)malloc(lend+len+7); strcpy(result, dir); /* Should test directory access here */ if (!result[lend-1]) result[lend-1] = '/'; strcat(result, pfx); strcat(result, "XXXXXX"); /* * NB - the following runes are probably BSD 4.3 specific - * in 4.3 mktemp returns "/" on error (!!!). If the directory * does not exist mktemp seems to succeed, although the * name is invalid. */ rtemp = mktemp(result); if (rtemp == result) return result; free(result); /* Assume errno is set by mktemp... */ return 0; }