home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / compat / getcwd.c < prev    next >
C/C++ Source or Header  |  1993-07-12  |  2KB  |  64 lines

  1. /* 
  2.  * getcwd.c --
  3.  *
  4.  *    This file provides an implementation of the getcwd procedure
  5.  *    that uses getwd, for systems with getwd but without getcwd.
  6.  *
  7.  * Copyright (c) 1993 The Regents of the University of California.
  8.  * All rights reserved.
  9.  *
  10.  * Permission is hereby granted, without written agreement and without
  11.  * license or royalty fees, to use, copy, modify, and distribute this
  12.  * software and its documentation for any purpose, provided that the
  13.  * above copyright notice and the following two paragraphs appear in
  14.  * all copies of this software.
  15.  * 
  16.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19.  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20.  *
  21.  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23.  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24.  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25.  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26.  */
  27.  
  28. #ifndef lint
  29. static char rcsid[] = "$Header: /user6/ouster/tcl/compat/RCS/getcwd.c,v 1.2 93/07/12 14:00:59 ouster Exp $ SPRITE (Berkeley)";
  30. #endif /* not lint */
  31.  
  32. #include "tclInt.h"
  33. #include "tclUnix.h"
  34.  
  35. extern char *getwd _ANSI_ARGS_((char *pathname));
  36.  
  37. char *
  38. getcwd(buf, size)
  39.     char *buf;            /* Where to put path for current directory. */
  40.     size_t size;        /* Number of bytes at buf. */
  41. {
  42.     char realBuffer[MAXPATHLEN+1];
  43.     int length;
  44.  
  45.     if (getwd(realBuffer) == NULL) {
  46.     /*
  47.      * There's not much we can do besides guess at an errno to
  48.      * use for the result (the error message in realBuffer isn't
  49.      * much use...).
  50.      */
  51.  
  52.     errno = EACCES;
  53.     return NULL;
  54.     }
  55.     length = strlen(realBuffer);
  56.     if (length >= size) {
  57.     errno = ERANGE;
  58.     return NULL;
  59.     }
  60.     strcpy(buf, realBuffer);
  61.     return buf;
  62. }
  63.  
  64.