annotate liboctave/tempnam.c @ 5210:996a08a3eb06 ss-2-9-0

[project @ 2005-03-15 20:46:03 by jwe]
author jwe
date Tue, 15 Mar 2005 20:46:03 +0000
parents 8256c4c57419
children 4c8a2e4e0717
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1048
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
1 /* Copyright (C) 1991, 1993 Free Software Foundation, Inc.
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
2 This file is part of the GNU C Library.
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
3
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
4 The GNU C Library is free software; you can redistribute it and/or
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
5 modify it under the terms of the GNU Library General Public License as
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
6 published by the Free Software Foundation; either version 2 of the
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
7 License, or (at your option) any later version.
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
8
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
9 The GNU C Library is distributed in the hope that it will be useful,
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
12 Library General Public License for more details.
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
13
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
14 You should have received a copy of the GNU Library General Public
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
15 License along with the GNU C Library; see the file COPYING.LIB. If
1315
611d403c7f3d [project @ 1995-06-25 19:56:32 by jwe]
jwe
parents: 1243
diff changeset
16 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
611d403c7f3d [project @ 1995-06-25 19:56:32 by jwe]
jwe
parents: 1243
diff changeset
17 Boston, MA 02111-1307, USA. */
1048
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
18
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
19 #ifdef HAVE_CONFIG_H
1243
668dc3c012b5 [project @ 1995-04-11 00:30:31 by jwe]
jwe
parents: 1048
diff changeset
20 #include <config.h>
1048
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
21 #endif
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
22
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
23 #ifndef HAVE_TEMPNAM
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
24
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
25 #include <stddef.h>
1351
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
26 #include <stdio.h>
1048
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
27 #include <stdlib.h>
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
28 #include <string.h>
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
29
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
30 extern char *__stdio_gen_tempname (const char *dir, const char *pfx,
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
31 int dir_search, size_t *lenptr,
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
32 FILE **streamptr);
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
33
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
34 /* Generate a unique temporary filename using up to five characters of PFX
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
35 if it is not NULL. The directory to put this file in is searched for
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
36 as follows: First the environment variable "TMPDIR" is checked.
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
37 If it contains the name of a writable directory, that directory is used.
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
38 If not and if DIR is not NULL, that value is checked. If that fails,
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
39 P_tmpdir is tried and finally "/tmp". The storage for the filename
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
40 is allocated by `malloc'. */
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
41 char *
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
42 tempnam (const char *dir, const char *pfx)
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
43 {
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
44 size_t len;
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
45 register char *s;
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
46 register char *t = __stdio_gen_tempname(dir, pfx, 1, &len, (FILE **) NULL);
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
47
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
48 if (t == NULL)
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
49 return NULL;
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
50
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
51 s = (char *) malloc(len);
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
52 if (s == NULL)
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
53 return NULL;
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
54
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
55 (void) memcpy(s, t, len);
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
56 return s;
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
57 }
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
58
5240771b9090 [project @ 1995-01-19 14:39:36 by jwe]
jwe
parents:
diff changeset
59 #endif