matlab_gs_putenv.c

Go to the documentation of this file.
00001 
00007 /* $Id: matlab_gs_putenv.c,v 1.3 2006/05/09 20:19:44 yarkhan Exp $ */
00008 /* $UTK_Copyright: $ */
00009 
00010 #include <stdio.h>
00011 #include <string.h>
00012 
00013 #include <matrix.h>
00014 #include <mex.h>
00015 
00016 #include "matlab_gs.h"
00017 
00026 void
00027 matlab_gs_putenv(int nlhs, mxArray *plhs[],
00028            int nrhs, const mxArray *prhs[] )
00029 {
00030   char *env_equal_val;
00031   int i, len, retval;
00032 
00033   /* Check arguments */
00034   if (nrhs != 2) {
00035     mexPrintf("Usage: gs_putenv('VAR=value') \n");
00036     goto error;
00037   }
00038 
00039   /* Get string */
00040   if (!mxIsChar(prhs[1])) goto error;
00041   len = (mxGetM(prhs[1]) * mxGetN(prhs[1]) * sizeof(mxChar)) + 1;
00042   if ((env_equal_val = matlab_gs_calloc(len, 1)) == NULL) goto error;
00043   if (mxGetString(prhs[1],env_equal_val,len) != 0) goto error;
00044   
00045   retval = putenv(env_equal_val);
00046 
00047   if (nlhs > 1) {
00048       plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
00049       mxGetPr(plhs[0])[0] = (double)retval;
00050   }
00051   
00052   /* Finalize */
00053   return;
00054 
00055 /* Error handling */
00056  error:
00057   for (i=0;i<nlhs;i++) plhs[i] = mxCreateDoubleMatrix(0,0,mxREAL);
00058   mexPrintf("Warning: GridSolve call failed: %d:%d: %s; %s\n", grpc_errno, grpc_minor_errno, grpc_error_string(grpc_errno), grpc_minor_error_string(grpc_minor_errno));  
00059   return;
00060 }