1/* tmpfil.c
2   Get a temporary file name.
3
4   Copyright (C) 1991, 1992, 1993, 2002 Ian Lance Taylor
5
6   This file is part of the Taylor UUCP package.
7
8   This program is free software; you can redistribute it and/or
9   modify it under the terms of the GNU General Public License as
10   published by the Free Software Foundation; either version 2 of the
11   License, or (at your option) any later version.
12
13   This program is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16   General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with this program; if not, write to the Free Software
20   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
21
22   The author of the program may be contacted at ian@airs.com.
23   */
24
25#include "uucp.h"
26
27#include "uudefs.h"
28#include "uuconf.h"
29#include "system.h"
30#include "sysdep.h"
31
32#define ZDIGS \
33  "0123456789abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-"
34#define CDIGS (sizeof ZDIGS - 1)
35
36/*ARGSUSED*/
37char *
38zstemp_file (qsys)
39     const struct uuconf_system *qsys ATTRIBUTE_UNUSED;
40{
41  static unsigned int icount;
42  const char *const zdigs = ZDIGS;
43  char ab[14];
44  pid_t ime;
45  int iset;
46
47  ab[0] = 'T';
48  ab[1] = 'M';
49  ab[2] = '.';
50
51  ime = getpid ();
52  iset = 3;
53  while (ime > 0 && iset < 10)
54    {
55      ab[iset] = zdigs[ime % CDIGS];
56      ime /= CDIGS;
57      ++iset;
58    }
59
60  ab[iset] = '.';
61  ++iset;
62
63  ab[iset] = zdigs[icount / CDIGS];
64  ++iset;
65  ab[iset] = zdigs[icount % CDIGS];
66  ++iset;
67
68  ab[iset] = '\0';
69
70  ++icount;
71  if (icount >= CDIGS * CDIGS)
72    icount = 0;
73
74#if SPOOLDIR_V2 || SPOOLDIR_BSD42
75  return zbufcpy (ab);
76#endif
77#if SPOOLDIR_BSD43 || SPOOLDIR_ULTRIX || SPOOLDIR_TAYLOR
78  return zsysdep_in_dir (".Temp", ab);
79#endif
80#if SPOOLDIR_HDB || SPOOLDIR_SVR4
81  return zsysdep_in_dir (qsys->uuconf_zname, ab);
82#endif
83}
84