Skip to content

Commit

Permalink
Merge pull request #223 from akgrant43/21462-Open-a-FileStream-based-…
Browse files Browse the repository at this point in the history
…on-fd-or-FILE

Include FilePlugin>>primitiveFileOpenUseFileDescriptor & primitiveFileOpenUseFile

Summary of changes:

- Rename primitiveFileOpenUseFileDescriptor to primitiveConnectToFileDescriptor
- Rename primitiveFileOpenUseFile to primitiveConnectToFile
- Include new primitives on all platforms (not just Pharo)
- Add support for Windows
- Bug fix pointer retrieval in primitiveConnectToFile
- Additional comments
  • Loading branch information
akgrant43 committed Mar 7, 2018
2 parents b8fba4c + de27253 commit 19a102b
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 124 deletions.
10 changes: 5 additions & 5 deletions platforms/Cross/plugins/FilePlugin/FilePlugin.h
Expand Up @@ -8,7 +8,9 @@
* EMAIL:
* RCSID: $Id$
*
* 2018-03-01 AKG add SqFileFileOpen() & sqFileFdOpen()
* 2018-03-06 AKG Rename sqFileFileOpen() & sqFileFdOpen() to
* sqConnectToFile() and sqConnectToFileDescriptor()
* 2018-03-01 AKG add sqFileFileOpen() & sqFileFdOpen()
* 2009-05-15 EEM add stdio flag; reorder SQFile to make it more compact
* 2005-03-26 IKP fix unaligned accesses to file member
* 2004-06-10 IKP 64-bit cleanliness
Expand Down Expand Up @@ -53,10 +55,8 @@ sqInt sqFileInit(void);
sqInt sqFileShutdown(void);
sqInt sqFileOpen(SQFile *f, char *sqFileName, sqInt sqFileNameSize, sqInt writeFlag);
sqInt sqFileOpenNew(SQFile *f, char *sqFileName, sqInt sqFileNameSize, sqInt *exists);
#if PharoVM
sqInt sqFileFdOpen(SQFile *f, int fd, sqInt writeFlag);
sqInt sqFileFileOpen(SQFile *f, FILE *inFile, sqInt writeFlag);
#endif
sqInt sqConnectToFileDescriptor(SQFile *f, int fd, sqInt writeFlag);
sqInt sqConnectToFile(SQFile *f, void *file, sqInt writeFlag);
size_t sqFileReadIntoAt(SQFile *f, size_t count, char *byteArrayIndex, size_t startIndex);
sqInt sqFileRenameOldSizeNewSize(char *sqOldName, sqInt sqOldNameSize, char *sqNewName, sqInt sqNewNameSize);
sqInt sqFileSetPosition(SQFile *f, squeakFileOffsetType position);
Expand Down
17 changes: 9 additions & 8 deletions platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c
Expand Up @@ -9,6 +9,7 @@
* RCSID: $Id$
*
* NOTES: See change log below.
* 2018-03-01 AKG Add sqFileFdOpen & sqFileFileOpen
* 2005-03-26 IKP fix unaligned accesses to file[Size] members
* 2004-06-10 IKP 64-bit cleanliness
* 1/28/02 Tim remove non-ansi stuff
Expand Down Expand Up @@ -475,31 +476,32 @@ sqFileOpenNew(SQFile *f, char *sqFileName, sqInt sqFileNameSize, sqInt *exists)
return interpreterProxy->success(false);
}

#if PharoVM
sqInt
sqFileFdOpen(SQFile *sqFile, int fd, sqInt writeFlag)
sqConnectToFileDescriptor(SQFile *sqFile, int fd, sqInt writeFlag)
{
/*
* Open the file with the supplied file descriptor in binary mode.
*
* writeFlag determines whether the file is read-only or writable.
* writeFlag determines whether the file is read-only or writable
* and must be compatible with the existing access.
* sqFile is populated with the file information.
* Smalltalk is reponsible for handling character encoding and
* line ends.
*/
FILE *file = fdopen(fd, writeFlag ? "wb" : "rb");
FILE *file = openFileDescriptor(fd, writeFlag ? "wb" : "rb");
if (!file)
return interpreterProxy->success(false);
return sqFileFileOpen(sqFile, file, writeFlag);
return sqConnectToFile(sqFile, (void *)file, writeFlag);
}

sqInt
sqFileFileOpen(SQFile *sqFile, FILE *file, sqInt writeFlag)
sqConnectToFile(SQFile *sqFile, void *file, sqInt writeFlag)
{
/*
* Populate the supplied SQFile structure with the supplied FILE.
*
* writeFlag indicates whether the file is read-only or writable.
* writeFlag indicates whether the file is read-only or writable
* and must be compatible with the existing access.
*/
setFile(sqFile, file);
setSize(sqFile, 0);
Expand All @@ -508,7 +510,6 @@ sqFileFileOpen(SQFile *sqFile, FILE *file, sqInt writeFlag)
sqFile->writable = writeFlag;
return 1;
}
#endif

/*
* Fill-in files with 3 handles for stdin, stdout and stderr as available and
Expand Down
29 changes: 17 additions & 12 deletions platforms/win32/plugins/FilePlugin/sqWin32FilePrims.c
Expand Up @@ -250,36 +250,41 @@ sqInt sqFileOpenNew(SQFile *f, char* fileNameIndex, sqInt fileNameSize, sqInt* e
return 1;
}

#if PharoVM
sqInt
sqFileFdOpen(SQFile *sqFile, int fd, sqInt writeFlag)
sqConnectToFileDescriptor(SQFile *sqFile, int fd, sqInt writeFlag)
{
/*
* Open the file with the supplied file descriptor in binary mode.
*
* writeFlag determines whether the file is read-only or writable.
* writeFlag determines whether the file is read-only or writable
* and must be compatible with the existing access.
* sqFile is populated with the file information.
* Smalltalk is reponsible for handling character encoding and
* line ends.
*
* Not supported on Windows
*/
return interpreterProxy->success(false);
HANDLE file = _fdopen(fd, writeFlag ? "wb" : "rb");
if (!file)
return interpreterProxy->success(false);
return sqConnectToFile(sqFile, file, writeFlag);
}

sqInt
sqFileFileOpen(SQFile *sqFile, FILE *file, sqInt writeFlag)
sqConnectToFile(SQFile *sqFile, void *file, sqInt writeFlag)
{
/*
* Populate the supplied SQFile structure with the supplied FILE.
*
* writeFlag indicates whether the file is read-only or writable.
*
* Not supported on Windows
* writeFlag indicates whether the file is read-only or writable
* and must be compatible with the existing access.
*/
return interpreterProxy->success(false);
sqFile->file = (HANDLE)file;
AddHandleToTable(win32Files, file);
/* setSize(sqFile, 0); */
sqFile->sessionID = thisSession;
sqFile->lastOp = 0; /* Unused on Win32 */
sqFile->writable = writeFlag;
return 1;
}
#endif



Expand Down

0 comments on commit 19a102b

Please sign in to comment.