Home | History | Annotate | Download | only in misc

Lines Matching refs:file

3  * File:
7 * This file contains the host wrapper functions for stdio, stdlib, etc.
9 * Modify this file to suit the needs of your particular system.
12 * a MIDI type 1 file that can be played. To maintain efficiency, data
16 * EAS_HW_FILE is a structure to support local file buffering. It
17 * comprises the OS File handle, some data related to the local file
23 * If the file system supports duplicate file handles and buffering,
25 * native file I/O routines.
27 * If the system has enough memory to support reading the entire file
29 * EAS_HWOpenFile and then close the file. Simply substitute a memory
30 * pointer for the FILE* pointer. Calls to EAS_HW_DupHandle will work
32 * of calling fclose, free the memory containing the file data.
37 * you may not use this file except in compliance with the License.
81 * and buffering into a single file. If the OS supports
82 * duplicate file handles natively, this code can be
87 FILE *pFile;
115 /* need to track file opens for duplicate handles */
227 * Open a file for read or write
233 EAS_HW_FILE *file;
243 /* find an empty entry in the file table */
244 file = hwInstData->files;
248 if (file->pFile == NULL)
250 /* open the file */
252 file->pFile = fopen((const char*) locator->path, "rb");
253 if (file->pFile == NULL)
257 EAS_ReportX(_EAS_SEVERITY_NOFILTER, "EAS_HWOpenFile: Open file %d\n", i);
261 file->bytesInBuffer = 0;
262 file->readIndex = 0;
263 file->filePos = 0;
264 file->dup = EAS_FALSE;
266 *pFile = file;
269 file++;
280 * Fill buffer from file
284 EAS_RESULT EAS_HWFillBuffer (EAS_HW_DATA_HANDLE hwInstData, EAS_FILE_HANDLE file)
286 /* reposition the file pointer */
287 if (fseek(file->pFile, file->filePos, SEEK_SET) != 0)
290 /* read some data from the file */
291 file->bytesInBuffer = (EAS_I32) fread(file->buffer, 1, EAS_FILE_BUFFER_SIZE, file->pFile);
292 file->readIndex = 0;
293 if (file->bytesInBuffer == 0)
302 * Read data from a file
306 EAS_RESULT EAS_HWReadFile (EAS_HW_DATA_HANDLE hwInstData, EAS_FILE_HANDLE file, void *pBuffer, EAS_I32 n, EAS_I32 *pBytesRead)
316 if (file->pFile == NULL)
320 EAS_ReportX(_EAS_SEVERITY_NOFILTER, "EAS_HWReadFile: Reading %d bytes from position %d\n", n, file->filePos);
327 temp = file->bytesInBuffer - file->readIndex;
332 EAS_HWMemCpy(p, &file->buffer[file->readIndex], temp);
334 file->readIndex += temp;
335 file->filePos += temp;
344 if ((result = EAS_HWFillBuffer(hwInstData, file)) != EAS_SUCCESS)
352 /* position the file pointer */
353 if (fseek(file->pFile, file->filePos, SEEK_SET) != 0)
358 temp = (EAS_I32) fread(p, 1, (size_t) bytesLeft, file->pFile);
360 file->filePos += temp;
363 file->bytesInBuffer = 0;
364 file->readIndex = 0;
390 * Read a byte from a file
394 EAS_RESULT EAS_HWGetByte (EAS_HW_DATA_HANDLE hwInstData, EAS_FILE_HANDLE file, void *p)
399 if (file->pFile == NULL)
403 if (file->readIndex >= file->bytesInBuffer)
405 if ((result = EAS_HWFillBuffer(hwInstData, file)) != EAS_SUCCESS)
409 if (file->bytesInBuffer == 0)
414 *((EAS_U8*) p) = file->buffer[file->readIndex++];
417 EAS_ReportX(_EAS_SEVERITY_NOFILTER, "EAS_HWGetByte: Reading from position %d, byte = 0x%02x\n", file->filePos, *(EAS_U8*)p);
420 file->filePos++;
428 * Read a 16-bit value from the file
431 EAS_RESULT EAS_HWGetWord (EAS_HW_DATA_HANDLE hwInstData, EAS_FILE_HANDLE file, void *p, EAS_BOOL msbFirst)
438 EAS_ReportX(_EAS_SEVERITY_NOFILTER, "EAS_HWGetWord: Reading 2 bytes from position %d\n", file->filePos);
441 /* read 2 bytes from the file */
442 if ((result = EAS_HWReadFile(hwInstData, file, c, 2, &count)) != EAS_SUCCESS)
458 * Read a 16-bit value from the file
461 EAS_RESULT EAS_HWGetDWord (EAS_HW_DATA_HANDLE hwInstData, EAS_FILE_HANDLE file, void *p, EAS_BOOL msbFirst)
468 EAS_ReportX(_EAS_SEVERITY_NOFILTER, "EAS_HWGetDWord: Reading 4 bytes from position %d\n", file->filePos);
471 /* read 4 bytes from the file */
472 if ((result = EAS_HWReadFile(hwInstData, file, c, 4, &count)) != EAS_SUCCESS)
488 * Returns the current location in the file
493 EAS_RESULT EAS_HWFilePos (EAS_HW_DATA_HANDLE hwInstData, EAS_FILE_HANDLE file, EAS_I32 *pPosition)
497 if (file->pFile == NULL)
500 *pPosition = file->filePos;
508 * Seek to a specific location in the file
513 EAS_RESULT EAS_HWFileSeek (EAS_HW_DATA_HANDLE hwInstData, EAS_FILE_HANDLE file, EAS_I32 position)
518 if (file->pFile == NULL)
522 EAS_ReportX(_EAS_SEVERITY_NOFILTER, "EAS_HWFileSeek: Seeking to new position %d\n", file->filePos);
526 newIndex = position - file->filePos + file->readIndex;
527 if ((newIndex >= 0) && (newIndex < file->bytesInBuffer))
529 file->readIndex = newIndex;
530 file->filePos = position;
535 file->filePos = position;
536 file->bytesInBuffer = 0;
537 file->readIndex = 0;
550 file, EAS_I32 position)
555 EAS_ReportX(_EAS_SEVERITY_NOFILTER, "EAS_HWFileSeekOfs: Seeking to new position %d\n", file->filePos + position);
559 if (file->pFile == NULL)
563 temp = position + file->readIndex;
564 if ((temp >= 0) && (temp < file->bytesInBuffer))
566 file->readIndex = temp;
567 file->filePos += position;
572 file->filePos += position;
573 file->bytesInBuffer = 0;
574 file->readIndex = 0;
582 * Return the file length
587 EAS_RESULT EAS_HWFileLength (EAS_HW_DATA_HANDLE hwInstData, EAS_FILE_HANDLE file, EAS_I32 *pLength)
592 if (file->pFile == NULL)
595 if ((pos = ftell(file->pFile)) == -1L)
597 if (fseek(file->pFile, 0L, SEEK_END) != 0)
599 if ((*pLength = ftell(file->pFile)) == -1L)
601 if (fseek(file->pFile, pos, SEEK_SET) != 0)
610 * Duplicate a file handle
614 EAS_RESULT EAS_HWDupHandle (EAS_HW_DATA_HANDLE hwInstData, EAS_FILE_HANDLE file, EAS_FILE_HANDLE* pDupFile)
621 if (file->pFile == NULL)
624 /* find an empty entry in the file table */
633 dupfile->filePos = file->filePos;
634 dupfile->pFile = file->pFile;
637 dupfile->dup = file->dup = EAS_TRUE;
706 /* no duplicates - close the file */