Skip to content

Commit

Permalink
FileAttributesPlugin: OSX and Windows fixes
Browse files Browse the repository at this point in the history
- typedef faStatStruct so that struct stat can be used on unix and
  struct _stat on Windows
- Remove reference from the support files to FileAttributesPlugin.c.
  This doesn't work as internal plugins have their symbols static,
  preventing external access.
  • Loading branch information
akgrant committed Oct 1, 2018
1 parent 2a0edb0 commit 3cf4474
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 140 deletions.
33 changes: 32 additions & 1 deletion platforms/Cross/plugins/FileAttributesPlugin/faCommon.c
Expand Up @@ -5,7 +5,7 @@
*/

#include "sq.h"
#include "faSupport.h"
#include "faCommon.h"

extern struct VirtualMachine * interpreterProxy;

Expand Down Expand Up @@ -34,3 +34,34 @@ char *pathName;
return faSetStPath(aFaPath, pathName, len);
}



/*
* faCharToByteArray
*
* Copy the supplied C string to a newly allocated ByteArray
*/
sqInt faCharToByteArray(const char *cBuf, sqInt *byteArrayOop)
{
unsigned char *byteArrayPtr;
sqInt len;
sqInt newByteArray;


/* We never return strings longer than PATH_MAX */
len = strlen(cBuf);
if (len >= FA_PATH_MAX) {
return -1 /* stringTooLong */;
}
newByteArray = interpreterProxy->instantiateClassindexableSize(interpreterProxy->classByteArray(), len);
if (!(newByteArray)) {
return interpreterProxy->primitiveFailFor(PrimErrNoMemory);
}
byteArrayPtr = interpreterProxy->arrayValueOf(newByteArray);
memcpy(byteArrayPtr, cBuf, len);
byteArrayOop[0] = newByteArray;
return 0;
}



14 changes: 14 additions & 0 deletions platforms/Cross/plugins/FileAttributesPlugin/faCommon.h
@@ -0,0 +1,14 @@
/*
* faCommon.h
*
* Declerations for FileAttributes platform independent functions.
*/

#include "faConstants.h"
#include "faSupport.h"


sqInt faSetStDirOop(fapath *aFaPath, sqInt pathNameOop);
sqInt faSetStPathOop(fapath *aFaPath, sqInt pathNameOop);
sqInt faCharToByteArray(const char *cBuf, sqInt *byteArrayOop);

10 changes: 0 additions & 10 deletions platforms/Cross/plugins/FileAttributesPlugin/faPlugin.h

This file was deleted.

6 changes: 3 additions & 3 deletions platforms/iOS/plugins/FileAttributesPlugin/Makefile
Expand Up @@ -2,9 +2,9 @@
# FileAttributesPlugin uses sq2uxPath() and ux2sqPath(), provided by sqUnixCharConv.h
#
#
SRCDIRS:=../../platforms/unix/vm
INCDIRS:=../../platforms/unix/vm
LIBSRC:=FileAttributesPlugin.c sqUnixCharConv.c
SRCDIRS:=../../platforms/unix/vm ../../platforms/unix/plugins/FileAttributesPlugin
INCDIRS:=../../platforms/unix/vm ../../platforms/unix/plugins/FileAttributesPlugin
LIBSRC:=FileAttributesPlugin.c sqUnixCharConv.c faSupport.c faCommon.c

include ../common/Makefile.plugin

5 changes: 2 additions & 3 deletions platforms/unix/plugins/FileAttributesPlugin/faSupport.c
Expand Up @@ -9,8 +9,7 @@
#include <assert.h>

#include "sq.h"
#include "faSupport.h"
#include "faPlugin.h"
#include "faCommon.h"

extern struct VirtualMachine * interpreterProxy;

Expand Down Expand Up @@ -222,7 +221,7 @@ char uxName[FA_PATH_MAX];
status = ux2sqPath(pathName, len, uxName, FA_PATH_MAX, 1);
if (!status)
return interpreterProxy->primitiveFailForOSError(FA_INVALID_ARGUMENTS);
status = byteArrayFromCStringto(uxName, &pathOop);
status = faCharToByteArray(uxName, &pathOop);
if (status)
return interpreterProxy->primitiveFailForOSError(status);
return pathOop;
Expand Down
10 changes: 2 additions & 8 deletions platforms/unix/plugins/FileAttributesPlugin/faSupport.h
@@ -1,16 +1,12 @@
#include <dirent.h>
#include <sys/stat.h>

# include "sqUnixCharConv.h"

/* REQUIRED: c file must have included standard squeak definitions */
#include "faConstants.h"


/* Maximum path length allowed on this platform */
#define FA_PATH_MAX PATH_MAX
#define PATH_SEPARATOR '/'

#include "sqUnixCharConv.h"

typedef struct stat faStatStruct;


Expand Down Expand Up @@ -50,9 +46,7 @@ typedef struct fapathstruct {
} fapath;

sqInt faSetStDir(fapath *aFaPath, char *pathName, int len);
sqInt faSetStDirOop(fapath *aFaPath, sqInt pathNameOop);
sqInt faSetStPath(fapath *aFaPath, char *pathName, int len);
sqInt faSetStPathOop(fapath *aFaPath, sqInt pathNameOop);
sqInt faSetStFile(fapath *aFaPath, char *pathName);
sqInt faSetPlatPath(fapath *aFaPath, char *pathName);
sqInt faSetPlatPathOop(fapath *aFaPath, sqInt pathNameOop);
Expand Down
5 changes: 2 additions & 3 deletions platforms/win32/plugins/FileAttributesPlugin/faSupport.c
Expand Up @@ -9,8 +9,7 @@
#include <assert.h>

#include "sq.h"
#include "faSupport.h"
#include "faPlugin.h"
#include "faCommon.h"

extern struct VirtualMachine * interpreterProxy;

Expand Down Expand Up @@ -354,7 +353,7 @@ char stName[FA_PATH_MAX];
if (!len)
return interpreterProxy->primitiveFailForOSError(FA_STRING_TOO_LONG);

status = byteArrayFromCStringto(stName, &pathOop);
status = faCharToByteArray(stName, &pathOop);
if (status)
return interpreterProxy->primitiveFailForOSError(status);
return pathOop;
Expand Down
3 changes: 0 additions & 3 deletions platforms/win32/plugins/FileAttributesPlugin/faSupport.h
@@ -1,9 +1,6 @@
#include <windows.h>
#include <sys/stat.h>

/* REQUIRED: c file must have included standard squeak definitions */
#include "faConstants.h"

/* Maximum path length allowed on this platform */
#define FA_PATH_MAX 4096
#define PATH_SEPARATOR '\\'
Expand Down

0 comments on commit 3cf4474

Please sign in to comment.