/*
    ####             #    #     # #
    #   #            #    #       #          The FreeWare C library for 
    #   #  ##   ###  #  # #     # ###             RISC OS machines
    #   # #  # #     # #  #     # #  #   ___________________________________
    #   # ####  ###  ##   #     # #  #                                      
    #   # #        # # #  #     # #  #    Please refer to the accompanying
    ####   ### ####  #  # ##### # ###    documentation for conditions of use
    ________________________________________________________________________

    File:    KernelSWIs.ReadVarVal.c
    Author:  Copyright  1994 Tim Browse
    Version: 1.00 (30 May 1994)
    Purpose: Function to read an environment variable's value.
*/

#include "swis.h"

#include "Desk.Core.h"
#include "Desk.KernelSWIs.h"
#include "Desk.SWI.h"


extern Desk_bool Desk_OS_ReadVarVal(const char *varname, char *buf, int bufsize)
{
  int result;
  
  /* Check for existence of this system variable */
  _swix( OS_ReadVarVal, _INR(0,2)|_OUT(2),
  	varname, buf, -1, &result
  	);
  /*Desk_SWI(3, 3, Desk_SWI_OS_ReadVarVal, varname, buf, -1, NULL, NULL, &result);*/
  if (result < 0)
  {
    /* Variable exists - read it and use text for file description */
    _swix( OS_ReadVarVal, _INR(0,4)|_OUT(2),
  	varname, buf, bufsize, 0, 0,
  	&result
  	);
    /*
    Desk_SWI(5, 3, Desk_SWI_OS_ReadVarVal,
        varname, buf, bufsize, 0, 0,
        NULL, NULL, &result);
   */
    /* Ensure correct termination */
    buf[result] = 0;

    return Desk_bool_TRUE;
  }
  
  /* Could not find it */
  return Desk_bool_FALSE;
}      

