home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / tcl / tcl7.0b1 / compat / getcwd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-03  |  2.0 KB  |  65 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/strtod.c,v 1.4 93/0
  30. 3/19 15:25:47 ouster Exp $ SPRITE (Berkeley)";
  31. #endif /* not lint */
  32.  
  33. #include "tclInt.h"
  34. #include "tclUnix.h"
  35.  
  36. extern char *getwd _ANSI_ARGS_((char *pathname));
  37.  
  38. char *
  39. getcwd(buf, size)
  40.     char *buf;            /* Where to put path for current directory. */
  41.     size_t size;        /* Number of bytes at buf. */
  42. {
  43.     char realBuffer[MAXPATHLEN+1];
  44.     int length;
  45.  
  46.     if (getwd(realBuffer) == NULL) {
  47.     /*
  48.      * There's not much we can do besides guess at an errno to
  49.      * use for the result (the error message in realBuffer isn't
  50.      * much use...).
  51.      */
  52.  
  53.     errno = EACCES;
  54.     return NULL;
  55.     }
  56.     length = strlen(realBuffer);
  57.     if (length >= size) {
  58.     errno = ERANGE;
  59.     return NULL;
  60.     }
  61.     strcpy(buf, realBuffer);
  62.     return buf;
  63. }
  64.  
  65.