home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / programm / programi / ixemupd_.lzh / ixemupd-920129 / stdlib / getenv.c next >
Encoding:
C/C++ Source or Header  |  1992-01-26  |  2.3 KB  |  91 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #define KERNEL
  21. #include "ixemul.h"
  22.  
  23. #if __GNUC__ != 2
  24. #define alloca __builtin_alloca
  25. #endif
  26.  
  27. extern int _dos20;
  28.  
  29. #define BASE_EXT_DECL
  30. #define BASE_PAR_DECL    
  31. #define BASE_PAR_DECL0    
  32. #define BASE_NAME    ix.ix_dos_base
  33. __inline static LONG GetVar(BASE_PAR_DECL const char* name, UBYTE* buffer, long int size, long int flags)
  34. {
  35.     BASE_EXT_DECL
  36.     register LONG res __asm("d0");
  37.     register void *a6 __asm ("a6");
  38.     register UBYTE* d1 __asm("d1");
  39.     register UBYTE* d2 __asm("d2");
  40.     register long int d3 __asm("d3");
  41.     register long int d4 __asm("d4");
  42.  
  43.     a6 = BASE_NAME;
  44.     d1 = name;
  45.     d2 = buffer;
  46.     d3 = size;
  47.     d4 = flags;
  48.     __asm volatile ("
  49.     jsr a6@(-0x38a)"
  50.     : "=r" (res)
  51.     : "r" (a6), "r" (d1), "r" (d2), "r" (d3), "r" (d4)
  52.     : "d0", "d1", "a0", "a1", "d2", "d3", "d4");
  53.     return res;
  54. }
  55.  
  56.  
  57. char *
  58. getenv (const char *var)
  59. {
  60.   int fd;
  61.   char *name, *result;
  62.   int len;
  63.   int omask;
  64. #define buf (u.u_getenv_buf)
  65.  
  66.   /* under 2.0 use the system function */
  67.   if (_dos20)
  68.     {
  69.       /* but when using the system, block signals */
  70.       omask = syscall (SYS_sigsetmask, ~0);
  71.       result = GetVar (var, buf, 255, 0) >= 0 ? buf : 0;
  72.       syscall (SYS_sigsetmask, omask);
  73.       return result;
  74.     }
  75.   else
  76.     {
  77.       name = alloca(strlen(var) + sizeof("env:") + 1);
  78.       strcpy(name, "env:");
  79.       strcat(name, var);
  80.       fd = syscall (SYS_open, name, 0);
  81.       if (fd >= 0)
  82.     {
  83.           len = syscall (SYS_read, fd, buf, 255);
  84.           if (len >= 0) buf[len] = 0;
  85.           syscall (SYS_close, fd);
  86.           return buf;
  87.         }
  88.       return NULL;
  89.     }
  90. }
  91.