/** * Tests for pcsl_file_get_time(). */ void testTimes() { int res; long time1, time2; int fileID; int i, j; res = pcsl_file_get_time(&dummy1, PCSL_FILE_TIME_LAST_MODIFIED, &time1); assertTrue("Time query succeeded for non-existent file", res == -1); res = pcsl_file_open(&file1, PCSL_FILE_O_RDWR | PCSL_FILE_O_TRUNC | PCSL_FILE_O_CREAT, (void **)&fileID); pcsl_file_close((void *)fileID); assertTrue("File creation failed", res == 0); res = pcsl_file_get_time(&file1, PCSL_FILE_TIME_LAST_MODIFIED, &time1); assertTrue("Time query failed", res == 0); res = pcsl_file_open(&file1, PCSL_FILE_O_RDWR | PCSL_FILE_O_APPEND, (void **)&fileID); assertTrue("File opening failed", res == 0); for (i = 0; i < 1000000; i++) { res = pcsl_file_write((void *)fileID, (unsigned char *)&time1, 4); assertTrue("Write failed", res == 4); } pcsl_file_close((void *)fileID); /* Writing 4 MB to a file should take several seconds */ res = pcsl_file_get_time(&file1, PCSL_FILE_TIME_LAST_MODIFIED, &time2); assertTrue("Time query failed", res == 0); assertTrue("Modification time should be greater", time2 > time1); for (j = 0; j < 10; j++) { res = pcsl_file_open(&file1, PCSL_FILE_O_RDWR | PCSL_FILE_O_APPEND, (void **)&fileID); assertTrue("File opening failed", res == 0); for (i = 0; i < 1000000; i++) { res = pcsl_file_read((void *)fileID, (unsigned char *)&time1, 4); assertTrue("Read failed", res == 4); } pcsl_file_close((void *)fileID); } /* Reading anything from a file shouldn't lead to modification time change */ res = pcsl_file_get_time(&file1, PCSL_FILE_TIME_LAST_MODIFIED, &time1); assertTrue("Time query failed", res == 0); assertTrue("Modification time shouldn't change", time1 == time2); pcsl_file_unlink(&file1); }
/* * Write to an open file in storage. Will write all of the bytes in the * buffer or pass back an error. * * If not successful *ppszError will set to point to an error string, * on success it will be set to NULL. */ void storageWrite(char** ppszError, int handle, char* buffer, long length) { long bytesWritten; *ppszError = NULL; bytesWritten = pcsl_file_write((void *)handle, (unsigned char*)buffer, length); REPORT_INFO2(LC_CORE, "storageWrite on fd %d res = %ld\n", handle, bytesWritten); if (-1 == bytesWritten) { *ppszError = getLastError("storageWrite()"); return; } if (bytesWritten != length) { *ppszError = "storage full"; return; } }
size_t OsFile_write(OsFile_Handle handle, const void *buffer, size_t size, size_t count) { return (pcsl_file_write(handle->pcsl_handle, (unsigned char*)buffer, (long)(size*count))) / size; }