plugins/include/files.inc
author David Anderson <dvander@alliedmods.net>
Wed May 16 01:17:14 2007 +0000 (2007-05-16)
changeset 800 432f5aed9b1e
parent 634 85108309e453
child 812 c8acd5c38374
permissions -rw-r--r--
fixed a bug where the JIT initiated the optimized stack top boundary check with a doubly relocated address, causing a rare bug with stack operations
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be used 
     8  * or modified under the Terms and Conditions of its License Agreement, which is found 
     9  * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
    10  * may change at any time.  To view the latest information, see:
    11  *   http://www.sourcemod.net/license.php
    12  *
    13  * Version: $Id$
    14  */
    15 
    16 #if defined _files_included
    17  #endinput
    18 #endif
    19 #define _files_included
    20 
    21 /* @global All paths in SourceMod natives are relative to the mod folder unless otherwise noted. */
    22 
    23 /**
    24  * File inode types.
    25  */
    26 enum FileType
    27 {
    28 	FileType_Unknown = 0,	/* Unknown file type (device/socket) */
    29 	FileType_Directory = 1,	/* File is a directory */
    30 	FileType_File = 2,		/* File is a file */
    31 };
    32 
    33 #define PLATFORM_MAX_PATH		256		/**< Maximum path length. */
    34 
    35 #define SEEK_SET 0						/**< Seek from start. */
    36 #define SEEK_CUR 1						/**< Seek from current position. */
    37 #define SEEK_END 2						/**< Seek from end position. */
    38 
    39 /**
    40  * Path types.
    41  */
    42 enum PathType
    43 {
    44 	Path_SM,		/**< SourceMod root folder */	
    45 };
    46 
    47 /**
    48  * @brief Builds a path relative to the SourceMod folder.
    49  *
    50  * @param type			Type of path to build as the base.
    51  * @param buffer		Buffer to store the path.
    52  * @param maxlength		Maximum length of buffer.
    53  * @param fmt			Format string.
    54  * @param ...			Format arguments.
    55  * @return				Number of bytes written to buffer (not including null terminator).
    56  */
    57 native BuildPath(PathType:type, String:buffer[], maxlength, const String:fmt[], any:...);
    58 
    59 /**
    60  * @brief Opens a directory/folder for contents enumeration.
    61  * @note Directories are closed with CloseHandle().
    62  * @note Directories Handles can be cloned.
    63  *
    64  * @param path			Path to open.
    65  * @return				A Handle to the directory, INVALID_HANDLE on open error.
    66  */
    67 native Handle:OpenDirectory(const String:path[]);
    68 
    69 /**
    70  * @brief Reads the current directory entry as a local filename, then moves to the next file.
    71  * @note Contents of buffers are undefined when returning false.
    72  * @note Both the '.' and '..' automatic directory entries will be retrieved for Windows and Linux.
    73  * 
    74  * @param dir			Handle to a directory.
    75  * @param buffer		String buffer to hold directory name.
    76  * @param maxlength		Maximum size of string buffer.
    77  * @param type			Optional variable to store the file type.
    78  * @return				True on success, false if there are no more files to read.
    79  * @error				Invalid or corrupt Handle. 
    80  */
    81 native bool:ReadDirEntry(Handle:dir, String:buffer[], maxlength, &FileType:type=FileType_Unknown);
    82 
    83 /**
    84  * @brief Opens a file.
    85  * @note Files are closed with CloseHandle().
    86  * @note File Handles can be cloned.
    87  *
    88  * @param file			File to open.
    89  * @param mode			Open mode.
    90  * @return				A Handle to the file, INVALID_HANDLE on open error.
    91  */
    92 native Handle:OpenFile(const String:file[], const String:mode[]);
    93 
    94 /**
    95  * @brief Deletes a file.
    96  *
    97  * @param path			Path of the file to delete.
    98  * @return				True on success, false otherwise.
    99  */
   100 native bool:DeleteFile(const String:path[]);
   101 
   102 /**
   103  * @brief Reads a line from a text file.
   104  *
   105  * @param hndl			Handle to the file.
   106  * @param buffer		String buffer to hold the line.
   107  * @param maxlength		Maximum size of string buffer.	
   108  * @return				True on success, false otherwise.
   109  */
   110 native bool:ReadFileLine(Handle:hndl, String:buffer[], maxlength);
   111 
   112 /**
   113  * @brief Tests if the end of file has been reached.
   114  *
   115  * @param file			Handle to the file.
   116  * @return				True if end of file has been reached, false otherwise.
   117  */
   118 native bool:IsEndOfFile(Handle:file);
   119 
   120 /**
   121  * @brief Sets the file position indicator.
   122  *
   123  * @param file			Handle to the file.
   124  * @param position		Position relative to what is specified in whence.
   125  * @param whence		Look at the SEEK_* definitions.
   126  * @return				True on success, false otherwise.
   127  */
   128 native bool:FileSeek(Handle:file, position, whence);
   129 
   130 /**
   131  * @brief Get current position in the file.
   132  *
   133  * @param file			Handle to the file.
   134  * @return				Value for the file position indicator.
   135  */
   136 native FilePosition(Handle:file);
   137 
   138 /**
   139  * @brief Checks if a file exists.
   140  *
   141  * @param path			Path to the file.
   142  * @return				True if the file exists, false otherwise.
   143  */
   144 native bool:FileExists(const String:path[]);
   145 
   146 /**
   147  * @brief Renames a file.
   148  *
   149  * @param newpath		New path to the file.
   150  * @param oldpath		Path to the existing file.
   151  * @return				True on success, false otherwise.
   152  */
   153 native bool:RenameFile(const String:newpath[], const String:oldpath[]);
   154 
   155 /**
   156  * @brief Checks if a directory exists.
   157  *
   158  * @param path			Path to the directory.
   159  * @return				True if the directory exists, false otherwise.
   160  */
   161 native bool:DirExists(const String:path[]);
   162 
   163 /**
   164  * @brief Get the file size in bytes.
   165  *
   166  * @param path			Path to the file.
   167  * @return				File size in bytes, -1 if file not found.
   168  */
   169 native FileSize(const String:path[]);
   170 
   171 /**
   172  * @brief Removes a directory.
   173  * @note On most Operating Systems you cannot remove a directory which has files inside it.
   174  *
   175  * @param path			Path to the directory.
   176  * @return				True on success, false otherwise.
   177  */
   178 native bool:RemoveDir(const String:path[]);
   179 
   180 /**
   181  * @brief Writes a line of text in a file.
   182  * @note This native will append the newline character.
   183  *
   184  * @param hndl			Handle to the file.
   185  * @param format		Formatting rules.
   186  * @param ...			Variable number of format parameters.
   187  * @return				True on success, false otherwise.
   188  */
   189 native bool:WriteFileLine(Handle:hndl, const String:format[], any:...);