static value extensionkit_create_temporary_file() { const char* tempFile = extensionkit::CreateTemporaryFile(NULL); if (tempFile != NULL) { return alloc_string_len(tempFile, strlen(tempFile)); } else { return alloc_null(); } }
static value extensionkit_get_public_documents_directory() { const char* dir = extensionkit::GetPublicDocumentsDirectory(); if (dir != NULL) { return alloc_string_len(dir, strlen(dir)); } else { return alloc_null(); } }
static value extensionkit_get_private_app_files_directory() { const char* dir = extensionkit::GetPrivateAppFilesDirectory(); if (dir != NULL) { return alloc_string_len(dir, strlen(dir)); } else { return alloc_null(); } }
static value extensionkit_get_temp_directory() { const char* dir = extensionkit::GetTempDirectory(); if (dir != NULL) { return alloc_string_len(dir, strlen(dir)); } else { return alloc_null(); } }
/** sys_env : void -> #list <doc>Return all the (key,value) pairs in the environment as a chained list</doc> **/ static value sys_env() { value result = alloc_array(0); #ifndef HX_WINRT char **e = environ; while( *e ) { char *x = strchr(*e,'='); if( x == NULL ) { e++; continue; } val_array_push(result,alloc_string_len(*e,(int)(x-*e))); val_array_push(result,alloc_string(x+1)); e++; } #endif return result; }
/** * Read whole file into ram **/ static value fileext_contents( value fname ) { val_check(fname, string); fio f; f.open(fname,alloc_string("r")); if(f.io == NULL) fileext_error("Unable to open file"); f.seek(0, SEEK_END); int len = f.tell(); f.seek(0, SEEK_SET); char *cb = (char *)malloc(len); if(cb == NULL) fileext_error("Out of memory"); int res = f.read(cb, 0, len); value s = alloc_string_len((const char *)cb,len); free(cb); return s; }