Parent Directory | Revision Log
Revision 1 - (view) (download)
1 : | ian | 1 | /* Files functions |
2 : | * | ||
3 : | * by the AMX Mod X Development Team | ||
4 : | * originally developed by OLO | ||
5 : | * | ||
6 : | * This file is provided as is (no warranties). | ||
7 : | */ | ||
8 : | |||
9 : | #if defined _file_included | ||
10 : | #endinput | ||
11 : | #endif | ||
12 : | #define _file_included | ||
13 : | |||
14 : | /* Reads content from directory. | ||
15 : | * Returns index of next element or 0 when end of dir. is reached. */ | ||
16 : | native read_dir(const dirname[],pos,output[],len,&outlen); | ||
17 : | |||
18 : | /* Reads line from file. Returns index of next line or 0 when end of file is reached. */ | ||
19 : | native read_file(const file[],line,text[],len,&txtlen); | ||
20 : | |||
21 : | /* Writes text to file. Function returns 0 on failure. | ||
22 : | * When line is set to -1, the text is added at the end of file. */ | ||
23 : | native write_file(const file[],const text[],line = -1); | ||
24 : | |||
25 : | /* Deletes file. Function returns 1 on success, 0 on failure. */ | ||
26 : | native delete_file(const file[]); | ||
27 : | |||
28 : | /* Checks for file. If file exists function returns 1, in other case 0. */ | ||
29 : | native file_exists(const file[]); | ||
30 : | |||
31 : | /* renames a file. returns 0 on failure, 1 on success. | ||
32 : | * if relative true, rename_file will act like other natives which | ||
33 : | * use the moddir as a base directory. otherwise, the current directory is | ||
34 : | * undefined (but assumed to be hlds). | ||
35 : | */ | ||
36 : | native rename_file(const oldname[], const newname[], relative=0); | ||
37 : | |||
38 : | /* Checks if a directory exists */ | ||
39 : | native dir_exists(const dir[]); | ||
40 : | |||
41 : | /* Returns a file size in bytes if flag is set to 0. | ||
42 : | * When flag is set to 1 returns number of lines in the file, | ||
43 : | * and when flags is 2, function returns 1 if the file ends | ||
44 : | * with line feed. If file doesn't exist returns -1. */ | ||
45 : | native file_size(const file[], flag=0); | ||
46 : | |||
47 : | #define SEEK_SET 0 | ||
48 : | #define SEEK_CUR 1 | ||
49 : | #define SEEK_END 2 | ||
50 : | |||
51 : | //Open a file, returns a handle or 0 on failure | ||
52 : | native fopen(const filename[],const mode[]); | ||
53 : | |||
54 : | //Closes a file handle | ||
55 : | native fclose(file); | ||
56 : | |||
57 : | #define BLOCK_INT 4 | ||
58 : | #define BLOCK_SHORT 2 | ||
59 : | #define BLOCK_CHAR 1 | ||
60 : | #define BLOCK_BYTE 1 | ||
61 : | |||
62 : | //The following functions work as such: | ||
63 : | // RAW - means the array you pass is a raw bytestream, for experts only | ||
64 : | // BLOCK - means you are passing in an array where each element will be written | ||
65 : | // NORMAL - means you are writing only one element | ||
66 : | // RAW and BLOCK return the number of blocks acted upon successfully | ||
67 : | // NORMAL returns 1 on success | ||
68 : | |||
69 : | native fread(file, &data, mode); | ||
70 : | native fread_blocks(file, data[], blocks, mode); | ||
71 : | native fread_raw(file, stream[], blocksize, blocks); | ||
72 : | native fwrite(file, data, mode); | ||
73 : | native fwrite_blocks(file, const data[], blocks, mode); | ||
74 : | native fwrite_raw(file, const stream[], blocksize, mode); | ||
75 : | |||
76 : | //Returns 1 if the file is ended, 0 otherwise | ||
77 : | native feof(file); | ||
78 : | |||
79 : | //Reads a line from a text file -- includes newline! | ||
80 : | native fgets(file, buffer[], maxlength); | ||
81 : | |||
82 : | //Writes a line to a text file. Returns # of characters written. | ||
83 : | native fputs(file, const text[]); | ||
84 : | |||
85 : | //Writes a line to the file | ||
86 : | native fprintf(file, const fmt[], {Float,Sql,Result,_}:...); | ||
87 : | |||
88 : | //Sets the current position in a file (see SEEK_ values above) | ||
89 : | native fseek(file, position, start); | ||
90 : | |||
91 : | //Returns the current position in a file | ||
92 : | native ftell(file); | ||
93 : | |||
94 : | //These are straight from the C standard. | ||
95 : | native fgetc(file); | ||
96 : | native fputc(file, data); | ||
97 : | native fungetc(file, data); | ||
98 : | |||
99 : | //Return the size of a file | ||
100 : | native filesize(const filename[], {Float,Sql,Result,_}:...); | ||
101 : | |||
102 : | //Attempts to remove a directory. | ||
103 : | //Note that you cannot remove a directory that has files on most | ||
104 : | // operating systems. | ||
105 : | native rmdir(const path[]); | ||
106 : | |||
107 : | //Delete a file (delete_file macro) | ||
108 : | native unlink(const filename[]); | ||
109 : | |||
110 : | //Returns a handle to a directory | ||
111 : | native open_dir(dir[], firstfile[], length); | ||
112 : | native next_file(dirh, buffer[], length); | ||
113 : | native close_dir(dirh); |
Contact | ViewVC Help |
Powered by ViewVC 1.0.4 |