mirror of
https://github.com/GnoConsortium/gno.git
synced 2025-01-20 06:30:12 +00:00
1 line
13 KiB
C
1 line
13 KiB
C
|
/*
* Copyright (c) Kopriha Software, 1990-1991
* All Rights Reserved
*
* Read.CC
*
* Description:
* This module exists to abstract the data of the file I/O
* primitives of GS/OS.
*
*
* History:Oct 13, 1990 Dave Created this file
*
* Feb 25, 1991 Dave Added I/O buffering
*
* May 26, 1991 Dave Added set EOF
*
* Jun 07, 1991 Dave Broke the single source into lots
* of small sources so we can build
* a library to use...
*
* Jun 30, 1991 Dave Added support for no target buffer
* (IE: This allows me to open a file
* with a buffer then do I/O to only
* that buffer - we will assume that
* the caller will know what he is doing).
*
* This functionallity is invoked when
* we are called with a data_buffer
* pointer to NULL (then the user must
* understand that the file_ptr->buffer
* is where he will find his data).
*
* Note: This functionallity is only
* implemented for the buffered I/O case!
*
*/
/*
* define DEBUG_CODE
* - add # to define to create the local
* debug code (IE:module)
*/
#ifndef _KS_FILEIO_
#include "ks.fileio.h"
#endif
#pragma noroot
/* ****************************************************************** *
* ks_file_read - Perform an read from an open file (possibly using *
* an internal buffer). *
* *
* History: Feb 26, 1991 Dave Created this routine *
* ****************************************************************** */
#undef ROUTINE_NAME
#define ROUTINE_NAME "ks_file_read"
KS_E_ERROR ks_file_read(KS_FILE_PTR file_ptr,
LongWord position,
LongWord data_size,
Pointer data_buffer)
{
/* ************************************************************** *
* Local declarations: *
* ************************************************************** */
KS_E_ERROR error; /* Holds error codes for subroutine*/
/* calls */
LongWord data_offset; /* Offset into the buffer to return*/
LongWord remaining_space; /* Space remaining in file buffer */
LongWord buffer_request; /* Size of each copy from the */
/* file buffer */
ROUTINE_ENTER();
/* ************************************************************** *
* Verify the structure ID passed in is the correct one. *
* ************************************************************** */
if (file_ptr->struct_id != KS_FILE_ID)
{
KS_ERROR(KS_E_INVALID_STRUCT_ID, KS_FILE_ID);
};
/* ************************************************************** *
* Zero the number of bytes transfered in the KS_FILE structure. *
* ************************************************************** */
file_ptr->data_size = 0;
/* ************************************************************** *
* If there is a buffer, then lets get data from the file buffer.*
* ************************************************************** */
if (file_ptr->buffer_size != NULL)
{
/* ********************************************************** *
* If we hit the end of file last time, then we have no *
* choice but to return an error. *
* ********************************************************** */
if (fi
|