added amb909 - LoadFileForMe()

This commit is contained in:
David Anderson 2007-10-22 19:26:45 +00:00
parent 50bbefa3ba
commit 468e6fb9dd
2 changed files with 49 additions and 0 deletions

View File

@ -824,6 +824,37 @@ static cell AMX_NATIVE_CALL amx_rename(AMX *amx, cell *params)
#endif #endif
} }
static cell LoadFileForMe(AMX *amx, cell *params)
{
int len;
char *file = get_amxstring(amx, params[1], 0, len);
char path[256];
build_pathname_r(path, sizeof(path), "%s", file);
byte *addr = LOAD_FILE_FOR_ME(path, &len);
if (addr == NULL)
{
return -1;
}
cell *buffer = get_amxaddr(amx, params[2]);
cell maxlength = params[3];
cell *bytes_avail = get_amxaddr(amx, params[4]);
*bytes_avail = len;
cell count;
for (count = 0; count < len && count < maxlength; count++)
{
buffer[count] = addr[count];
}
FREE_FILE(addr);
return count;
}
AMX_NATIVE_INFO file_Natives[] = AMX_NATIVE_INFO file_Natives[] =
{ {
{"delete_file", delete_file}, {"delete_file", delete_file},
@ -859,5 +890,6 @@ AMX_NATIVE_INFO file_Natives[] =
{"rmdir", amx_rmdir}, {"rmdir", amx_rmdir},
{"fputs", amx_fputs}, {"fputs", amx_fputs},
{"rename_file", amx_rename}, {"rename_file", amx_rename},
{"LoadFileForMe", LoadFileForMe},
{NULL, NULL} {NULL, NULL}
}; };

View File

@ -115,3 +115,20 @@ native unlink(const filename[]);
native open_dir(dir[], firstfile[], length); native open_dir(dir[], firstfile[], length);
native next_file(dirh, buffer[], length); native next_file(dirh, buffer[], length);
native close_dir(dirh); native close_dir(dirh);
/**
* Loads a file using the LoadFileForMe engine function.
*
* The data is truncated if there is not enough space. No null-terminator
* is applied; the data is the raw contents of the file.
*
* @param file File to load (may be a file from the GCF).
* @param buffer Buffer to store file contents.
* @param maxlength Maximum size of the file buffer.
* @param length Variable to store the file length. This may return
* a number larger than the buffer size.
* @return -1 if the file could not be loaded. Otherwise,
* the number of cells actually written to the buffer
* are returned.
*/
native LoadFileForMe(const file[], buffer[], maxlength, &length=0);