home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / programm / programi / ixemupd_.lzh / ixemupd-920129 / stdlib / setenv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-26  |  2.3 KB  |  86 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. #define alloca __builtin_alloca
  24.  
  25. #define BASE_EXT_DECL
  26. #define BASE_PAR_DECL    
  27. #define BASE_PAR_DECL0    
  28. #define BASE_NAME    ix.ix_dos_base
  29. __inline static BOOL SetVar(BASE_PAR_DECL UBYTE* name, UBYTE* buffer, long int size, long int flags)
  30. {
  31.     BASE_EXT_DECL
  32.     register BOOL res __asm("d0");
  33.     register void *a6 __asm ("a6");
  34.     register UBYTE* d1 __asm("d1");
  35.     register UBYTE* d2 __asm("d2");
  36.     register long int d3 __asm("d3");
  37.     register long int d4 __asm("d4");
  38.  
  39.     a6 = BASE_NAME;
  40.     d1 = name;
  41.     d2 = buffer;
  42.     d3 = size;
  43.     d4 = flags;
  44.     __asm volatile ("
  45.     jsr a6@(-0x384)"
  46.     : "=r" (res)
  47.     : "r" (a6), "r" (d1), "r" (d2), "r" (d3), "r" (d4)
  48.     : "d0", "d1", "a0", "a1", "d2", "d3", "d4");
  49.     return res;
  50. }
  51.  
  52. extern int _dos20;
  53.  
  54. int
  55. setenv (const char *var, const char *val, ...)
  56. {
  57.   int fd;
  58.   char *name;
  59.   int result = -1;
  60.   int omask;
  61.  
  62.   /* under 2.0, use the system function */
  63.   if (_dos20)
  64.     {
  65.       /* but when using the system, block signals, sigh.. */
  66.       omask = syscall (SYS_sigsetmask , ~0);
  67.       result = SetVar (var, val, -1, 0) ? 0 : -1;
  68.       syscall (SYS_sigsetmask, omask);
  69.       return result;
  70.     }
  71.   else
  72.     {
  73.       name = alloca (strlen(var) + sizeof("env:") + 1);
  74.       strcpy(name, "env:");
  75.       strcat(name, var);
  76.       fd = syscall (SYS_open, name, O_WRONLY|O_CREAT|O_TRUNC, 0666);
  77.       if (fd >= 0)
  78.         {
  79.           syscall (SYS_write, fd, val, strlen (val));
  80.           syscall (SYS_close, fd);
  81.           result = 0;
  82.         }
  83.       return result;
  84.     }
  85. }
  86.