home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / DMAKE38C.ZIP / MAC / TEMPNAM.C < prev    next >
C/C++ Source or Header  |  1992-01-23  |  2KB  |  73 lines

  1. /* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/mac/tempnam.c,v 1.1 1992/01/24 03:29:52 dvadura Exp $
  2. -- SYNOPSIS -- Fake tempnam function for the mac
  3. --
  4. -- DESCRIPTION
  5. --  Get a temporary file name.
  6. --
  7. -- AUTHOR
  8. --      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  9. --      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  10. --
  11. --
  12. -- COPYRIGHT
  13. --      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
  14. -- 
  15. --      This program is free software; you can redistribute it and/or
  16. --      modify it under the terms of the GNU General Public License
  17. --      (version 1), as published by the Free Software Foundation, and
  18. --      found in the file 'LICENSE' included with this distribution.
  19. -- 
  20. --      This program is distributed in the hope that it will be useful,
  21. --      but WITHOUT ANY WARRANTY; without even the implied warrant of
  22. --      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. --      GNU General Public License for more details.
  24. -- 
  25. --      You should have received a copy of the GNU General Public License
  26. --      along with this program;  if not, write to the Free Software
  27. --      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28. --
  29. -- LOG
  30. --     $Log: tempnam.c,v $
  31.  * Revision 1.1  1992/01/24  03:29:52  dvadura
  32.  * dmake Version 3.8, Initial revision
  33.  *
  34. */
  35.  
  36.  
  37. #include "extern.h"
  38. #include <StdIO.h>
  39. #include <String.h>
  40.  
  41.  
  42.  
  43. /*
  44.  * Try to open a temporary file in the given directory (if non-NULL)
  45.  * with the given prefix (if non-NULL).
  46.  *
  47.  * We ignore the directory argument.
  48.  */
  49. PUBLIC char *tempnam (char * /* pDir */, char * pPrefix) {
  50.     char *pName;
  51.     char *pFullName;
  52.  
  53.     pName = tmpnam ((char *) NULL);
  54.  
  55.     /* Assume that if the name returned by tmpnam is not being used,
  56.        the name with the prefix is also not being used. */
  57.     pFullName = MALLOC (((pPrefix != NULL) ? strlen (pPrefix) : 0) +
  58.                         strlen (pName) + 1, char);
  59.  
  60.     /* Copy in the name if we successfully allocated space for it. */
  61.     if (pFullName != NULL) {
  62.         if (pPrefix != NULL) {
  63.             strcpy (pFullName, pPrefix);
  64.         } else {
  65.             *pFullName = '\0';
  66.         } /* if ... else */
  67.  
  68.         strcat (pFullName, pName);
  69.     } /* if */
  70.     
  71.     return (pFullName);
  72. } /* PUBLIC char *tempnam () */
  73.