RexxObject *SystemInterpreter::buildEnvlist() { BufferClass *newBuffer; /* Buffer object to hold env */ char **Environment; /* environment pointer */ size_t size = 0; /* size of the new buffer */ char *curr_dir; /* current directory */ char *New; /* starting address of buffer */ Environment = getEnvironment(); /* get the ptr to the environ */ for (;*Environment != NULL;Environment++) { size += strlen(*Environment); /* calculate the size for all */ size++; /* environment variables+'\0' */ } /* now get current dir */ if (!size) { return OREF_NULL; /* no envrionment ! */ } if (!(curr_dir=(char *)malloc(PATH_MAX + 3)))/* malloc storage for cwd*/ { reportException(Error_System_service); } // start with a copy of the current working directory SystemInterpreter::getCurrentWorkingDirectory(curr_dir); size += strlen(curr_dir); /* add the space for curr dir */ size++; /* and its terminating '\0' */ size += sizeof(size_t); /* this is for the size itself*/ /* Now we have the size for */ /* allocating the new buffer */ newBuffer = new_buffer(size); /* let's do it */ /* Get starting address of buf*/ New = newBuffer->getData(); ((ENVENTRY*)New)->size = size; /* first write the size */ New += sizeof(size_t); /* update the pointer */ /* now write the curr dir */ memcpy(New,curr_dir,strlen(curr_dir)); New += strlen(curr_dir); /* update the pointer */ memcpy(New,"\0",1); /* write the terminator */ New++; /* update the pointer */ Environment = getEnvironment(); /* reset to begin of environ */ /* Loop through environment */ /* and copy all entries to the*/ /* buffer, each terminating */ /* with '\0' */ for (;*Environment != NULL;Environment++) { /* copy the entry */ memcpy(New,*Environment,strlen(*Environment)); New += strlen(*Environment); /* update the pointer */ memcpy(New,"\0",1); /* write the terminator */ New++; /* update the pointer */ } free(curr_dir); /* free curr dir buffer */ return newBuffer; /* return the pointer */ }
/** * Pop an environment for the SysEndLocal() BIF. * * @param context The current activation context. * * @return Always returns FALSE. This is a NOP on Windows. */ RexxObject *SystemInterpreter::popEnvironment(RexxActivation *context) { BufferClass *Current = (BufferClass *)context->popEnvironment();/* block, if ixisted. */ if (TheNilObject == Current) /* nothing saved? */ { return TheFalseObject; /* return failure value */ } else { /* restore everything */ restoreEnvironment(Current->getData()); return TheTrueObject; /* this worked ok */ } }
static void SNCBufFinish(Buffer buffer) { BufferClass super; SNCBuf sncbuf; SNC snc; Pool pool; AVERT(Buffer, buffer); sncbuf = BufferSNCBuf(buffer); AVERT(SNCBuf, sncbuf); pool = BufferPool(buffer); snc = PoolSNC(pool); /* Put any segments which haven't bee popped onto the free list */ sncPopPartialSegChain(snc, buffer, NULL); sncbuf->sig = SigInvalid; /* finish the superclass fields last */ super = BUFFER_SUPERCLASS(SNCBufClass); super->finish(buffer); }
static Res BufferInit(Buffer buffer, BufferClass klass, Pool pool, Bool isMutator, ArgList args) { AVERT(BufferClass, klass); return klass->init(buffer, pool, isMutator, args); }
/** * Read the program meta data and the image data from a file, with * image validation. * * @param handle The input file handle. * * @return A BufferClass instance containing the program data, or OREF_NULL * if the file is not a valid image. */ BufferClass *ProgramMetaData::read(RexxString *fileName, FILE *handle) { bool badVersion = false; size_t headerSize = getHeaderSize(); size_t readSize; // now read the control info readSize = fread((char *)this, 1, headerSize, handle); // if we could read the header, validate all of the meta information if (readSize < headerSize || !validate(badVersion)) { // if this failed because we couldn't read in the required header, or // because of the version signature, we need to raise an error now. if (readSize < headerSize || badVersion) { fclose(handle); reportException(Error_Program_unreadable_version, fileName); } // if it didn't validate, it might be because we have a unix-style "hash bang" line at the // beginning of the file. The first read in bit has a "#!", then we need to read // beyond the first linend and try again. if (fileTag[0] == '#' && fileTag[1] == '!') { // back to the start (ok, just past the hash bang) fseek(handle, 2, SEEK_SET); while (true) { if (fread(fileTag, 1, 1, handle) <= 0) { fclose(handle); return OREF_NULL; } // if we hit a newline, this is our stopping point. // NB: this works with both \n and \r\n sequences. if (fileTag[0] == '\n') { break; } // ok, try to read the control information one more time. // if this doesn't work, no point in being pushy about it. readSize = fread((char *)this, 1, headerSize, handle); // if we could read the header, validate all of the meta information if (readSize < headerSize || !validate(badVersion)) { fclose(handle); /* close the file */ // if because we couldn't read in the required header, or // because of a bad version sig, we can close now if (readSize < headerSize || badVersion) { reportException(Error_Program_unreadable_version, fileName); } return OREF_NULL; } } } } BufferClass *buffer = new_buffer(imageSize); ProtectedObject p(buffer); readSize = fread(buffer->getData(), 1, imageSize, handle); if (readSize < imageSize) { fclose(handle); reportException(Error_Program_unreadable_version, fileName); return OREF_NULL; } return buffer; }