Skip to content

Commit

Permalink
Fix a comment typo in sqImageFileAccessViaStdio.h.
Browse files Browse the repository at this point in the history
Fix some formatting in sqWin32FilePrims.c; if( is bad; if is a keyword, not
a function. char* foo is bad; the type of bar in "char* foo, bar;" is char.
This is why in K&R the asterisk is always associated with the variable, not the
base type. Returns should be om their own line for breakpointing when debugging.
  • Loading branch information
eliotmiranda committed Oct 8, 2022
1 parent 378818e commit af9b525
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
3 changes: 1 addition & 2 deletions platforms/Cross/vm/sqImageFileAccessViaStdio.h
@@ -1,11 +1,10 @@
/****************************************************************************
* PROJECT: API for reading/writing image files
* FILE: sqImageFileAccessViaStdio.h
*
*/

/* This is a lowest common denominator, a poor man's image file interface built
* using macros around stdio. Stdio is poor because it provdes buffered i/o.
* using macros around stdio. Stdio is poor because it provides buffered i/o.
* Much better is unbuffered i/o using the platform's native file interface.
* Apart from a few fields in the image header the entire image is read and
* written in segments, many megabytes in size. Unbuffered is the way to go.
Expand Down
62 changes: 32 additions & 30 deletions platforms/win32/plugins/FilePlugin/sqWin32FilePrims.c
Expand Up @@ -105,7 +105,7 @@ sqFileClose(SQFile *f)

if (!sqFileValid(f))
FAIL();
if(!CloseHandle(FILE_HANDLE(f)))
if (!CloseHandle(FILE_HANDLE(f)))
FAIL();
RemoveHandleFromTable(win32Files, FILE_HANDLE(f));
f->file = NULL;
Expand All @@ -115,14 +115,14 @@ sqFileClose(SQFile *f)
}

sqInt
sqFileDeleteNameSize(char* fileNameIndex, sqInt fileNameSize)
sqFileDeleteNameSize(char *fileNameIndex, sqInt fileNameSize)
{
WCHAR *win32Path = NULL;

/* convert the file name into a null-terminated C string */
ALLOC_WIN32_PATH(win32Path, fileNameIndex, fileNameSize);

if(hasCaseSensitiveDuplicate(win32Path))
if (hasCaseSensitiveDuplicate(win32Path))
FAIL();

/* DeleteFile will not delete a file with the read-only attribute set
Expand All @@ -138,7 +138,7 @@ sqFileDeleteNameSize(char* fileNameIndex, sqInt fileNameSize)
the parent directory wont be empty. */
SetFileAttributesW(win32Path, FILE_ATTRIBUTE_NORMAL);

if(!DeleteFileW(win32Path))
if (!DeleteFileW(win32Path))
FAIL();

return 1;
Expand Down Expand Up @@ -177,7 +177,7 @@ sqFileInit(void)
sqInt sqFileShutdown(void) { return 1; }

sqInt
sqFileOpen(SQFile *f, char* fileNameIndex, sqInt fileNameSize, sqInt writeFlag)
sqFileOpen(SQFile *f, char *fileNameIndex, sqInt fileNameSize, sqInt writeFlag)
{
/* Opens the given file using the supplied sqFile structure
to record its state. Fails with no side effects if f is
Expand Down Expand Up @@ -219,7 +219,7 @@ sqFileOpen(SQFile *f, char* fileNameIndex, sqInt fileNameSize, sqInt writeFlag)
}

sqInt
sqFileOpenNew(SQFile *f, char* fileNameIndex, sqInt fileNameSize, sqInt* exists)
sqFileOpenNew(SQFile *f, char *fileNameIndex, sqInt fileNameSize, sqInt *exists)
{
HANDLE h;
WCHAR *win32Path = NULL;
Expand All @@ -233,7 +233,7 @@ sqFileOpenNew(SQFile *f, char* fileNameIndex, sqInt fileNameSize, sqInt* exists)
hasCaseSensitiveDuplicate() treats some paths as duplicates that
CreateFileW() doesn't, sqFileOpenNew() will fail like sqFileOpen() would
*/
if(hasCaseSensitiveDuplicate(win32Path)) {
if (hasCaseSensitiveDuplicate(win32Path)) {
f->sessionID = 0;
FAIL();
}
Expand All @@ -244,12 +244,13 @@ sqFileOpenNew(SQFile *f, char* fileNameIndex, sqInt fileNameSize, sqInt* exists)
CREATE_NEW, /* Only create and open if it doesn't exist */
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
NULL /* No template */);
if(h == INVALID_HANDLE_VALUE) {
if (h == INVALID_HANDLE_VALUE) {
f->sessionID = 0;
if (GetLastError() == ERROR_FILE_EXISTS)
*exists = true;
FAIL();
} else {
}
else {
f->sessionID = thisSession;
f->file = (HANDLE)h;
f->writable = true;
Expand Down Expand Up @@ -354,7 +355,7 @@ sqFileDescriptorType(int fdNum)
}

size_t
sqFileReadIntoAt(SQFile *f, size_t count, char* byteArrayIndex, size_t startIndex)
sqFileReadIntoAt(SQFile *f, size_t count, char *byteArrayIndex, size_t startIndex)
{
/* Read count bytes from the given file into byteArray starting at
startIndex. byteArray is the address of the first byte of a
Expand All @@ -376,7 +377,7 @@ sqFileReadIntoAt(SQFile *f, size_t count, char* byteArrayIndex, size_t startInde
}

sqInt
sqFileRenameOldSizeNewSize(char* oldNameIndex, sqInt oldNameSize, char* newNameIndex, sqInt newNameSize)
sqFileRenameOldSizeNewSize(char *oldNameIndex, sqInt oldNameSize, char *newNameIndex, sqInt newNameSize)
{
WCHAR *oldPath = NULL;
WCHAR *newPath = NULL;
Expand All @@ -385,9 +386,9 @@ sqFileRenameOldSizeNewSize(char* oldNameIndex, sqInt oldNameSize, char* newNameI
ALLOC_WIN32_PATH(oldPath, oldNameIndex, oldNameSize);
ALLOC_WIN32_PATH(newPath, newNameIndex, newNameSize);

if(hasCaseSensitiveDuplicate(oldPath))
if (hasCaseSensitiveDuplicate(oldPath))
FAIL();
if(!MoveFileW(oldPath, newPath))
if (!MoveFileW(oldPath, newPath))
FAIL();

return 1;
Expand Down Expand Up @@ -445,8 +446,7 @@ sqFileTruncate(SQFile *f, squeakFileOffsetType offset)
if (!sqFileValid(f))
FAIL();
SetFilePointer(FILE_HANDLE(f), ofs.dwLow, &ofs.dwHigh, FILE_BEGIN);
if(!SetEndOfFile(FILE_HANDLE(f))) return 0;
return 1;
return SetEndOfFile(FILE_HANDLE(f));
}

sqInt
Expand All @@ -462,7 +462,7 @@ sqFileValid(SQFile *f)
}

size_t
sqFileWriteFromAt(SQFile *f, size_t count, char* byteArrayIndex, size_t startIndex)
sqFileWriteFromAt(SQFile *f, size_t count, char *byteArrayIndex, size_t startIndex)
{
/* Write count bytes to the given writable file starting at startIndex
in the given byteArray. (See comment in sqFileReadIntoAt for interpretation
Expand All @@ -486,7 +486,8 @@ sqFileWriteFromAt(SQFile *f, size_t count, char* byteArrayIndex, size_t startInd
/***************************************************************************/
/* Image file functions */
/***************************************************************************/
int sqImageFileClose(sqImageFile h)
int
sqImageFileClose(sqImageFile h)
{
SetEndOfFile((HANDLE)(h-1));
return CloseHandle((HANDLE)(h-1));
Expand All @@ -499,19 +500,19 @@ sqImageFileOpen(const char *fileName, const char *mode)
WCHAR *win32Path = NULL;
HANDLE h;

if(!mode) return 0;
if (!mode)
return 0;
modePtr = mode;
while(*modePtr)
{
if(*modePtr == 'w') writeFlag = 1;
while (*modePtr) {
if (*modePtr == 'w') writeFlag = 1;
/* Note: We cannot append here */
if(*modePtr == 'a') return 0;
if (*modePtr == 'a') return 0;
modePtr++;
}
}
/* convert the file name into a null-terminated C string */
ALLOC_WIN32_PATH(win32Path, fileName, -1);

if(hasCaseSensitiveDuplicate(win32Path))
if (hasCaseSensitiveDuplicate(win32Path))
return 0;

h = CreateFileW(win32Path,
Expand All @@ -522,7 +523,7 @@ sqImageFileOpen(const char *fileName, const char *mode)
FILE_ATTRIBUTE_NORMAL,
NULL /* No template */);

if(h == INVALID_HANDLE_VALUE)
if (h == INVALID_HANDLE_VALUE)
return 0;

return (usqIntptr_t)h+1;
Expand Down Expand Up @@ -554,13 +555,13 @@ sqImageFileRead(void *ptr, size_t sz, size_t count, sqImageFile h)
if (!ret || dwReallyRead != toRead) {
DWORD err = GetLastError();
if (sqMessageBox(MB_ABORTRETRYIGNORE, TEXT("VM Warning"), TEXT("Image file read problem (%d out of %d bytes read)"), dwReallyRead, toRead)
== IDABORT) return (size_t)(reallyRead / sz);
== IDABORT)
return reallyRead / sz;
sqImageFileSeek(h, position);
reallyRead = 0;
}

}
return (reallyRead / sz);
return reallyRead / sz;
}

squeakFileOffsetType
Expand Down Expand Up @@ -598,12 +599,13 @@ sqImageFileWrite(const void *ptr, size_t sz, size_t count, sqImageFile h)
if (!ret || dwReallyWritten != toWrite) {
DWORD err = GetLastError();
if (sqMessageBox(MB_ABORTRETRYIGNORE, TEXT("VM Warning"), TEXT("Image file read problem (%d out of %d bytes read)"), dwReallyWritten, toWrite)
== IDABORT) return (size_t)(reallyWritten / sz);
== IDABORT)
return reallyWritten / sz;
sqImageFileSeek(h, position);
reallyWritten = 0;
}
}
return (size_t) (reallyWritten / sz);
return reallyWritten / sz;
}

squeakFileOffsetType
Expand Down

0 comments on commit af9b525

Please sign in to comment.