home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fs.zip / octave / octave-2.1.23 / liboctave / lo-sysdep.cc < prev    next >
C/C++ Source or Header  |  2000-01-15  |  3KB  |  136 lines

  1. /*
  2.  
  3. Copyright (C) 1996, 1997 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. /*
  24.  
  25. The function gethostname was adapted from a similar function from GNU
  26. Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free
  27. Software Foundation, Inc.
  28.  
  29. */
  30.  
  31. /* Modified by Klaus Gebhardt, 1999 */
  32.  
  33. #ifdef HAVE_CONFIG_H
  34. #include <config.h>
  35. #endif
  36.  
  37. #include <string>
  38.  
  39. #include <iostream.h>
  40.  
  41. #ifdef HAVE_UNISTD_H
  42. #ifdef HAVE_SYS_TYPES_H
  43. #include <sys/types.h>
  44. #endif
  45. #include <unistd.h>
  46. #endif
  47.  
  48. #ifdef __EMX__
  49. #include <stdlib.h>
  50. #endif
  51.  
  52. #if ! defined (HAVE_GETHOSTNAME) && defined (HAVE_SYS_UTSNAME_H)
  53. #include <sys/utsname.h>
  54. #endif
  55.  
  56. #include "lo-utils.h"
  57. #include "lo-error.h"
  58. #include "pathlen.h"
  59.  
  60. string
  61. octave_getcwd (void)
  62. {
  63.   string retval;
  64.  
  65.   char buf[MAXPATHLEN];
  66.  
  67.   char *tmp = 0;
  68.  
  69. #if defined (__EMX__)
  70.   tmp = _getcwd2 (buf, MAXPATHLEN);
  71. #elif defined (HAVE_GETCWD)
  72.   tmp = getcwd (buf, MAXPATHLEN);
  73. #elif defined (HAVE_GETWD)
  74.   tmp = getwd (buf);
  75. #endif
  76.  
  77.   if (tmp)
  78.     retval = tmp;
  79.   else
  80.     (*current_liboctave_error_handler) ("unable to find current directory");
  81.  
  82.   return retval;
  83. }
  84.  
  85. bool
  86. octave_chdir (const string& path)
  87. {
  88. #if defined (__EMX__)
  89.   int retval = -1;
  90.  
  91.   char *tmp_path = strsave (path.c_str ());
  92.  
  93.   if (path.length () == 2 && path[1] == ':')
  94.     {
  95.       char *upper_case_dir_name = strupr (tmp_path);
  96.       _chdrive (upper_case_dir_name[0]);
  97.       if (_getdrive () == upper_case_dir_name[0])
  98.     retval = _chdir2 ("/");
  99.     }
  100.   else
  101.     retval = _chdir2 (tmp_path);
  102.  
  103.   delete [] tmp_path;
  104.  
  105.   return retval;
  106. #else
  107.   return chdir (path.c_str ());
  108. #endif
  109. }
  110.  
  111. #if ! defined (HAVE_GETHOSTNAME) && defined (HAVE_SYS_UTSNAME_H)
  112.  
  113. int
  114. gethostname (char *name, int namelen)
  115. {
  116.   int i;
  117.   struct utsname ut;
  118.  
  119.   --namelen;
  120.  
  121.   uname (&ut);
  122.   i = strlen (ut.nodename) + 1;
  123.   strncpy (name, ut.nodename, i < namelen ? i : namelen);
  124.   name[namelen] = '\0';
  125.  
  126.   return 0;
  127. }
  128.  
  129. #endif
  130.  
  131. /*
  132. ;;; Local Variables: ***
  133. ;;; mode: C++ ***
  134. ;;; End: ***
  135. */
  136.