Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileAttributesPlugin 2.0.0: Fixes UTF8 on Windows #285

Merged
merged 8 commits into from Oct 3, 2018
67 changes: 67 additions & 0 deletions platforms/Cross/plugins/FileAttributesPlugin/faCommon.c
@@ -0,0 +1,67 @@
/*
* faCommon.c
*
* Provides a number of platform independent functions for FileAttributesPlugin.
*/

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

extern struct VirtualMachine * interpreterProxy;


sqInt faSetStDirOop(fapath *aFaPath, sqInt pathNameOop)
{
int len;
char *pathName;


len = interpreterProxy->stSizeOf(pathNameOop);
pathName = interpreterProxy->arrayValueOf(pathNameOop);
return faSetStDir(aFaPath, pathName, len);
}



sqInt faSetStPathOop(fapath *aFaPath, sqInt pathNameOop)
{
int len;
char *pathName;


len = interpreterProxy->stSizeOf(pathNameOop);
pathName = interpreterProxy->arrayValueOf(pathNameOop);
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);

32 changes: 32 additions & 0 deletions platforms/Cross/plugins/FileAttributesPlugin/faConstants.h
@@ -0,0 +1,32 @@
/*
* faConstants.h
*
* File Attributes constants
*
* Note that these must be kept in sync with their definition in
* FileAttributesPlugin errors / status protocol.
*
*/
#define FA_SUCCESS 0

#define FA_STRING_TOO_LONG -1
#define FA_STAT_FAILED -2
#define FA_CANT_STAT_PATH -3
#define FA_GET_ATTRIBUTES_FAILED -4
#define FA_TIME_CONVERSION_FAILED -5
#define FA_INVALID_ARGUMENTS -6
#define FA_CORRUPT_VALUE -7
#define FA_CANT_READ_LINK -8
#define FA_CANT_OPEN_DIR -9
#define FA_CANT_ALLOCATE_MEMORY -10
#define FA_INVALID_REQUEST -11
#define FA_UNABLE_TO_CLOSE_DIR -12
#define FA_UNSUPPORTED_OPERATION -13
#define FA_UNEXPECTED_ERROR -14
#define FA_INTERPRETER_ERROR -15 /* Actual error flagged in interpreterProxy */
#define FA_CANT_READ_DIR -16



#define FA_NO_MORE_DATA 1

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