1
0
forked from 0ad/0ad

1) removed scaffolding from file

2) VFS: add path_copy convenience routine
3) various lib code: removed unnecessary const cluttering things (like
const char* _const_ name in param list)

This was SVN commit r1483.
This commit is contained in:
janwas 2004-12-09 23:12:02 +00:00
parent cc02422908
commit 9d317d8164
21 changed files with 100 additions and 117 deletions

View File

@ -109,7 +109,7 @@ static size_t n_root_dir_len;
// return the native equivalent of the given relative portable path
// (i.e. convert all '/' to the platform's directory separator)
// makes sure length < PATH_MAX.
int file_make_native_path(const char* const path, char* const n_path)
int file_make_native_path(const char* path, char* n_path)
{
return convert_path(n_path, path, TO_NATIVE);
}
@ -117,7 +117,7 @@ int file_make_native_path(const char* const path, char* const n_path)
// return the portable equivalent of the given relative native path
// (i.e. convert the platform's directory separators to '/')
// makes sure length < PATH_MAX.
int file_make_portable_path(const char* const n_path, char* const path)
int file_make_portable_path(const char* n_path, char* path)
{
return convert_path(path, n_path, TO_PORTABLE);
}
@ -127,7 +127,7 @@ int file_make_portable_path(const char* const n_path, char* const path)
// (i.e. convert all '/' to the platform's directory separator).
// also prepends current directory => n_full_path is absolute.
// makes sure length < PATH_MAX.
int file_make_full_native_path(const char* const path, char* const n_full_path)
int file_make_full_native_path(const char* path, char* n_full_path)
{
strcpy(n_full_path, n_root_dir);
return convert_path(n_full_path+n_root_dir_len, path, TO_NATIVE);
@ -138,7 +138,7 @@ int file_make_full_native_path(const char* const path, char* const n_full_path)
// n_full_path is absolute; if it doesn't match the current dir, fail.
// (note: portable paths are always relative to file_rel_chdir root).
// makes sure length < PATH_MAX.
int file_make_full_portable_path(const char* const n_full_path, char* const path)
int file_make_full_portable_path(const char* n_full_path, char* path)
{
if(strncmp(n_full_path, n_root_dir, n_root_dir_len) != 0)
return -1;
@ -157,7 +157,7 @@ int file_make_full_portable_path(const char* const n_full_path, char* const path
// easiest portable way to find our install directory.
//
// can only be called once, by design (see below). rel_path is trusted.
int file_rel_chdir(const char* argv0, const char* const rel_path)
int file_rel_chdir(const char* argv0, const char* rel_path)
{
const char* msg = 0;
@ -256,28 +256,10 @@ typedef std::vector<const DirEnt*> DirEnts;
typedef DirEnts::const_iterator DirEntCIt;
typedef DirEnts::reverse_iterator DirEntRIt;
static bool dirent_less(const DirEnt* const d1, const DirEnt* const d2)
static bool dirent_less(const DirEnt* d1, const DirEnt* d2)
{ return d1->name.compare(d2->name) < 0; }
#include "timer.h"
static double totstat;
static double totpush;
static double totclose;
void dump2(void)
{
debug_out("TOTAL TIME %g ms\n\n", totstat*1e3);
debug_out("TOTAL TIME %g ms\n\n", totpush*1e3);
debug_out("TOTAL TIME %g ms\n\n", totclose*1e3);
}
// call <cb> for each file and subdirectory in <dir> (alphabetical order),
// passing the entry name (not full path!), stat info, and <user>.
//
@ -294,10 +276,8 @@ void dump2(void)
// special-case Zip files anyway.
// the advantage here is simplicity, and sparing callbacks the trouble
// of converting from/to native path (we just give 'em the dirent name).
int file_enum(const char* const dir, const FileCB cb, const uintptr_t user)
int file_enum(const char* dir, const FileCB cb, const uintptr_t user)
{
double t0,t1;
// full path for stat
char n_path[PATH_MAX];
n_path[PATH_MAX-1] = '\0';
@ -314,7 +294,7 @@ double t0,t1;
int ret;
// [16.6ms]
DIR* const os_dir = opendir(n_path);
DIR* os_dir = opendir(n_path);
if(!os_dir)
return ERR_PATH_NOT_FOUND;
@ -379,11 +359,6 @@ double t0,t1;
// [2.5ms]
closedir(os_dir);
ONCE(atexit(dump2));
// [5.8ms]
std::sort(dirents.begin(), dirents.end(), dirent_less);
@ -391,7 +366,7 @@ ONCE(atexit(dump2));
memset(&s, 0, sizeof(s));
for(DirEntCIt it = dirents.begin(); it != dirents.end(); ++it)
{
const DirEnt* const ent = *it;
const DirEnt* ent = *it;
const char* name_c = ent->name.c_str();
s.st_mode = ent->st_mode;
s.st_size = ent->st_size;
@ -417,7 +392,7 @@ ONCE(atexit(dump2));
// get file status. output param is zeroed on error.
int file_stat(const char* const path, struct stat* const s)
int file_stat(const char* path, struct stat* s)
{
memset(s, 0, sizeof(struct stat));
@ -464,7 +439,7 @@ static const u32 FILE_MAGIC = FOURCC('F','I','L','E');
#endif
static int file_validate(const uint line, File* const f)
static int file_validate(const uint line, File* f)
{
const char* msg = "";
int err = -1;
@ -508,7 +483,7 @@ do\
while(0);
int file_open(const char* const p_fn, const uint flags, File* const f)
int file_open(const char* p_fn, const uint flags, File* f)
{
// zero output param in case we fail below.
memset(f, 0, sizeof(File));
@ -564,7 +539,7 @@ invalid_f:
}
int file_close(File* const f)
int file_close(File* f)
{
CHECK_FILE(f);
@ -621,7 +596,7 @@ int file_close(File* const f)
// starts transferring to/from the given buffer.
// no attempt is made at aligning or padding the transfer.
int file_start_io(File* const f, const off_t ofs, size_t size, void* const p, FileIO* io)
int file_start_io(File* f, off_t ofs, size_t size, void* p, FileIO* io)
{
// zero output param in case we fail below.
memset(io, 0, sizeof(FileIO));
@ -922,8 +897,8 @@ skip_issue:
// (quasi-parallel, without the complexity of threads).
//
// return number of bytes transferred (see above), or a negative error code.
ssize_t file_io(File* const f, const off_t data_ofs, size_t data_size, void* const data_buf,
const FileIOCB cb, const uintptr_t ctx) // optional
ssize_t file_io(File* f, off_t data_ofs, size_t data_size, void* data_buf,
FileIOCB cb, uintptr_t ctx) // optional
{
#ifdef PARANOIA
debug_out("file_io fd=%d size=%d ofs=%d\n", f->fd, data_size, data_ofs);
@ -1161,7 +1136,7 @@ static const uint MAX_MAP_REFS = 255;
// rationale: reference counting is required for zip_map: several
// Zip "mappings" each reference one ZArchive's actual file mapping.
// implement it here so that we also get refcounting for normal files.
int file_map(File* const f, void*& p, size_t& size)
int file_map(File* f, void*& p, size_t& size)
{
p = 0;
size = 0;
@ -1209,7 +1184,7 @@ have_mapping:
// the mapping will be removed (if still open) when its file is closed.
// however, map/unmap calls should still be paired so that the mapping
// may be removed when no longer needed.
int file_unmap(File* const f)
int file_unmap(File* f)
{
CHECK_FILE(f);
@ -1225,7 +1200,7 @@ int file_unmap(File* const f)
return 0;
// no more references: remove the mapping
void* const p = f->mapping;
void* p = f->mapping;
f->mapping = 0;
// don't clear f->size - the file is still open.

View File

@ -73,13 +73,13 @@ enum
//
// relative paths (relative to root, established with file_rel_chdir)
extern int file_make_native_path(const char* const path, char* const n_path);
extern int file_make_portable_path(const char* const n_path, char* const path);
extern int file_make_native_path(const char* path, char* n_path);
extern int file_make_portable_path(const char* n_path, char* path);
// as above, but with full native paths (portable paths are always relative).
// prepends current directory, resp. makes sure it matches the given path.
extern int file_make_full_native_path(const char* const path, char* const n_full_path);
extern int file_make_full_portable_path(const char* const n_full_path, char* const path);
extern int file_make_full_native_path(const char* path, char* n_full_path);
extern int file_make_full_portable_path(const char* n_full_path, char* path);
// set current directory to rel_path, relative to the path to the executable,
@ -99,7 +99,7 @@ extern int file_rel_chdir(const char* argv0, const char* rel_path);
// called by file_enum for each entry in the directory.
// name doesn't include path!
// return non-zero to immediately abort; file_enum will return that value.
typedef int(*FileCB)(const char* const name, const struct stat* s, const uintptr_t user);
typedef int(*FileCB)(const char* name, const struct stat* s, const uintptr_t user);
// call <cb> for each file and subdirectory in <dir> (alphabetical order),
// passing the entry name (not full path!), stat info, and <user>.

View File

@ -6,7 +6,7 @@ extern int res_reload(const char* fn);
// (wdir_watch limitation)
extern int res_watch_dir(const char* const path, intptr_t* const watch);
extern int res_watch_dir(const char* path, intptr_t* watch);
extern int res_cancel_watch(const intptr_t watch);

View File

@ -169,7 +169,7 @@ static int Mem_reload(Mem* m, const char* fn, Handle hm)
//////////////////////////////////////////////////////////////////////////////
static void heap_free(void* const raw_p, const size_t raw_size, const uintptr_t ctx)
static void heap_free(void* raw_p, size_t raw_size, uintptr_t ctx)
{
UNUSED(raw_size);
UNUSED(ctx);
@ -178,7 +178,7 @@ static void heap_free(void* const raw_p, const size_t raw_size, const uintptr_t
}
static void* heap_alloc(const size_t raw_size, uintptr_t& ctx)
static void* heap_alloc(size_t raw_size, uintptr_t& ctx)
{
ctx = 0;
void* raw_p = malloc(raw_size);
@ -194,7 +194,7 @@ static size_t pool_pos;
static const size_t POOL_CAP = 8*MB; // TODO: user editable
static void pool_free(void* const raw_p, const size_t raw_size, const uintptr_t ctx)
static void pool_free(void* raw_p, size_t raw_size, uintptr_t ctx)
{
UNUSED(raw_p);

View File

@ -8,8 +8,7 @@
extern "C" {
#endif
typedef void(*MEM_DTOR)(void* const p, const size_t size, const uintptr_t ctx);
// VC6 requires const here if the actual implementations define as such.
typedef void(*MEM_DTOR)(void* p, size_t size, uintptr_t ctx);
// mem_alloc flags
enum

View File

@ -116,7 +116,7 @@ static int Tex_reload(Tex* t, const char* fn, Handle h)
}
Handle tex_load(const char* const fn, int scope)
Handle tex_load(const char* fn, int scope)
{
return h_alloc(H_Tex, fn, scope);
}
@ -158,7 +158,7 @@ int tex_id(const Handle h)
static int tex_validate(const uint line, const Tex* const t)
static int tex_validate(const uint line, const Tex* t)
{
const char* msg = 0;
int err = -1;

View File

@ -5,7 +5,7 @@
// load and return a handle to the texture given in <fn>.
// supports RAW, BMP, JP2, PNG, TGA, DDS
extern Handle tex_load(const char* const fn, int scope = 0);
extern Handle tex_load(const char* fn, int scope = 0);
extern int tex_bind(Handle ht);
extern int tex_id(Handle ht);

View File

@ -10,13 +10,13 @@
#include <string.h>
int res_reload(const char* const fn)
int res_reload(const char* fn)
{
return h_reload(fn);
}
int res_watch_dir(const char* const path, intptr_t* const watch)
int res_watch_dir(const char* path, intptr_t* watch)
{
char n_path[PATH_MAX];
CHECK_ERR(file_make_full_native_path(path, n_path));

View File

@ -1001,7 +1001,7 @@ if(file_type == FT_OGG)
// open and return a handle to a sound file's data.
static Handle snd_data_load(const char* const fn, const bool stream)
static Handle snd_data_load(const char* fn, bool stream)
{
// don't allow reloading stream objects
// (both references would read from the same file handle).
@ -1187,7 +1187,7 @@ static void list_foreach(void(*cb)(VSrc*), uint skip = 0, uint end_idx = 0)
}
static bool is_greater(const VSrc* const s1, const VSrc* const s2)
static bool is_greater(const VSrc* s1, const VSrc* s2)
{
return s1->cur_pri > s2->cur_pri;
}
@ -1477,7 +1477,7 @@ static int VSrc_reload(VSrc* vs, const char* fn, Handle hvs)
//
// note: RES_UNIQUE forces each instance to get a new resource
// (which is of course what we want).
Handle snd_open(const char* const snd_fn, const bool is_stream)
Handle snd_open(const char* snd_fn, bool is_stream)
{
uint flags = 0;
if(is_stream)

View File

@ -294,7 +294,7 @@ static inline bool dds_fmt(u8* ptr, size_t size)
}
static inline bool dds_ext(const char* const ext)
static inline bool dds_ext(const char* ext)
{
return !strcmp(ext, ".dds");
}
@ -466,7 +466,7 @@ static inline bool tga_fmt(u8* ptr, size_t size)
}
static inline bool tga_ext(const char* const ext)
static inline bool tga_ext(const char* ext)
{
return !strcmp(ext, ".tga");
}
@ -612,7 +612,7 @@ static inline bool bmp_fmt(u8* p, size_t size)
}
static inline bool bmp_ext(const char* const ext)
static inline bool bmp_ext(const char* ext)
{
return !strcmp(ext, ".bmp");
}
@ -726,7 +726,7 @@ static inline bool raw_fmt(u8* p, size_t size)
}
static inline bool raw_ext(const char* const ext)
static inline bool raw_ext(const char* ext)
{
return !strcmp(ext, ".raw");
}
@ -787,7 +787,7 @@ static inline bool png_fmt(u8* ptr, size_t size)
}
static inline bool png_ext(const char* const ext)
static inline bool png_ext(const char* ext)
{
return !strcmp(ext, ".png");
}
@ -825,9 +825,9 @@ struct PngMemFile
};
// pass data from PNG file in memory to libpng
static void png_read(png_struct* const png_ptr, u8* const data, const png_size_t length)
static void png_read(png_struct* png_ptr, u8* data, png_size_t length)
{
PngMemFile* const f = (PngMemFile*)png_ptr->io_ptr;
PngMemFile* f = (PngMemFile*)png_ptr->io_ptr;
void* src = (u8*)(f->p + f->pos);
@ -937,7 +937,7 @@ ret:
// write libpng output to PNG file
static void png_write(png_struct* const png_ptr, u8* const data, const png_size_t length)
static void png_write(png_struct* png_ptr, u8* data, png_size_t length)
{
void* p = (void*)data;
Handle hf = *(Handle*)png_ptr->io_ptr;
@ -1051,7 +1051,7 @@ static inline bool jp2_fmt(u8* p, size_t size)
}
static inline bool jp2_ext(const char* const ext)
static inline bool jp2_ext(const char* ext)
{
return !strcmp(ext, ".jp2");
}
@ -1168,7 +1168,7 @@ static const int num_codecs = sizeof(codecs) / sizeof(codecs[0]);
int tex_load(const char* const fn, TexInfo* t)
int tex_load(const char* fn, TexInfo* t)
{
// load file
void* _p = 0;

View File

@ -120,7 +120,7 @@
// if path is invalid (see source for criteria), print a diagnostic message
// (indicating line number of the call that failed) and
// return a negative error code. used by CHECK_PATH.
static int path_validate(const uint line, const char* const path)
static int path_validate(const uint line, const char* path)
{
size_t path_len = 0; // counted as we go; checked against max.
@ -186,6 +186,13 @@ ok:
#define CHECK_PATH(path) CHECK_ERR(path_validate(__LINE__, path))
// convenience function
static inline void path_copy(char* dst, const char* src)
{
strncpy(dst, src, VFS_MAX_PATH);
}
// combine <path1> and <path2> into one path, and write to <dst>.
// if necessary, a directory separator is added between the paths.
// each may be empty, filenames, or full paths.
@ -428,7 +435,7 @@ struct TDir
};
int TDir::add_subdir(const char* const dir_name)
int TDir::add_subdir(const char* dir_name)
{
if(find_file(dir_name))
{
@ -532,7 +539,7 @@ void TDir::displayR(int indent_level)
// recurse over all subdirs
for(TDirIt dir_it = subdirs.begin(); dir_it != subdirs.end(); ++dir_it)
{
TDir* const subdir = &dir_it->second;
TDir* subdir = &dir_it->second;
const char* subdir_name = dir_it->first.c_str();
// write subdir's name
@ -765,7 +772,7 @@ private:
// [total time 21ms, with ~2000 file's (includes add_file cost)]
static int zip_cb(const char* path, const struct stat* s, uintptr_t user)
{
ZipCBParams* const params = (ZipCBParams*)user;
ZipCBParams* params = (ZipCBParams*)user;
const TLoc* loc = params->loc;
char* last_path = params->last_path;
size_t& last_path_len = params->last_path_len;
@ -793,7 +800,7 @@ static int zip_cb(const char* path, const struct stat* s, uintptr_t user)
// archiver placing directories before subdirs or files that
// reference them (WinZip doesn't).
strncpy(last_path, path, VFS_MAX_PATH);
path_copy(last_path, path);
last_path_len = path_len;
last_dir = dir;
}
@ -1132,7 +1139,7 @@ int vfs_unmount(const char* p_real_path)
// if <path> or its ancestors are mounted,
// return a VFS path that accesses it.
// used when receiving paths from external code.
int vfs_make_vfs_path(const char* const path, char* const vfs_path)
int vfs_make_vfs_path(const char* path, char* vfs_path)
{
for(MountIt it = mounts.begin(); it != mounts.end(); ++it)
{
@ -1226,7 +1233,7 @@ static int VDir_reload(VDir* vd, const char* path, Handle)
// <v_dir> need not end in '/'; we add it if not present.
// directory contents are cached here; subsequent changes to the dir
// are not returned by this handle. rationale: see VDir definition.
Handle vfs_open_dir(const char* const v_dir)
Handle vfs_open_dir(const char* v_dir)
{
return h_alloc(H_VDir, v_dir, RES_NO_CACHE);
// must not cache, since the position in file array
@ -1257,7 +1264,7 @@ int vfs_close_dir(Handle& hd)
// finally, allocating a copy is not so good because it has to be
// freed by the user (won't happen). returning a volatile pointer
// to the string itself via c_str is the only remaining option.
int vfs_next_dirent(const Handle hd, vfsDirEnt* ent, const char* const filter)
int vfs_next_dirent(const Handle hd, vfsDirEnt* ent, const char* filter)
{
H_DEREF(hd, VDir, vd);
@ -1656,7 +1663,7 @@ static ssize_t vfs_timed_io(const Handle hf, const size_t size, void** p, FileIO
//
// note: we need the Handle return value for Tex.hm - the data pointer
// must be protected against being accidentally free-d in that case.
Handle vfs_load(const char* const v_fn, void*& p, size_t& size, uint flags /* default 0 */)
Handle vfs_load(const char* v_fn, void*& p, size_t& size, uint flags /* default 0 */)
{
#ifdef PARANOIA
debug_out("vfs_load v_fn=%s\n", v_fn);
@ -1731,7 +1738,7 @@ ret:
// caveat: pads file to next max(4kb, sector_size) boundary
// (due to limitation of Win32 FILE_FLAG_NO_BUFFERING I/O).
// if that's a problem, specify FILE_NO_AIO when opening.
int vfs_store(const char* const v_fn, void* p, const size_t size, uint flags /* default 0 */)
int vfs_store(const char* v_fn, void* p, const size_t size, uint flags /* default 0 */)
{
Handle hf = vfs_open(v_fn, flags|FILE_WRITE);
if(hf <= 0)

View File

@ -102,7 +102,7 @@ const size_t ECDR_SIZE = 22;
// return -1 if file is obviously not a valid Zip archive,
// otherwise 0. used as early-out test in lookup_init (see call site).
static inline int z_validate(const void* const file, const size_t size)
static inline int z_validate(const void* file, size_t size)
{
// make sure it's big enough to check the header and for
// z_find_ecdr to succeed (if smaller, it's definitely bogus).
@ -117,7 +117,7 @@ static inline int z_validate(const void* const file, const size_t size)
// find "End of Central Dir Record" in file.
// z_validate has made sure size >= ECDR_SIZE.
// return -1 on failure (output param invalid), otherwise 0.
static int z_find_ecdr(const void* const file, const size_t size, const u8*& ecdr_)
static int z_find_ecdr(const void* file, size_t size, const u8*& ecdr_)
{
// early out: check expected case (ECDR at EOF; no file comment)
const u8* ecdr = (const u8*)file + size - ECDR_SIZE;
@ -159,7 +159,7 @@ found_ecdr:
// make sure the LFH fields match those passed (from the CDFH).
// only used in PARANOIA builds - costs time when opening archives.
// return -1 on error or mismatch, otherwise 0.
static int z_verify_lfh(const void* const file, const off_t lfh_ofs, const off_t file_ofs)
static int z_verify_lfh(const void* file, const off_t lfh_ofs, const off_t file_ofs)
{
assert(lfh_ofs < file_ofs); // header comes before file
@ -225,7 +225,7 @@ static time_t convert_dos_date(u16 fatdate, u16 fattime)
// if cdfh is valid and describes a file, extract its name, offset and size
// for use in z_enum_files (passes it to lookup).
// return -1 on error (output params invalid), or 0 on success.
static int z_extract_cdfh(const u8* cdfh, const ssize_t bytes_left, const char*& fn, size_t& fn_len, ZLoc* const loc)
static int z_extract_cdfh(const u8* cdfh, ssize_t bytes_left, const char*& fn, size_t& fn_len, ZLoc* loc)
{
// sanity check: did we even read the CDFH?
if(bytes_left < CDFH_SIZE)
@ -305,9 +305,9 @@ static int z_extract_cdfh(const u8* cdfh, const ssize_t bytes_left, const char*&
// fn (filename) is not necessarily 0-terminated!
// loc is only valid during the callback! must be copied or saved.
typedef int(*CDFH_CB)(const uintptr_t user, const i32 idx, const char* const fn, const size_t fn_len, const ZLoc* const loc);
typedef int(*CDFH_CB)(uintptr_t user, i32 idx, const char* fn, size_t fn_len, const ZLoc* loc);
static int z_enum_files(const void* const file, const size_t size, const CDFH_CB cb, const uintptr_t user)
static int z_enum_files(const void* file, const size_t size, const CDFH_CB cb, const uintptr_t user)
{
// find "End of Central Directory Record"
const u8* ecdr;
@ -459,8 +459,8 @@ static void strcpy_lower(char* dst, const char* src)
// notes:
// - fn (filename) is not necessarily 0-terminated!
// - loc is only valid during the callback! must be copied or saved.
static int lookup_add_file_cb(const uintptr_t user, const i32 idx,
const char* const fn, const size_t fn_len, const ZLoc* const loc)
static int lookup_add_file_cb(uintptr_t user, i32 idx,
const char* fn, size_t fn_len, const ZLoc* loc)
{
LookupInfo* li = (LookupInfo*)user;
@ -499,6 +499,7 @@ static int lookup_add_file_cb(const uintptr_t user, const i32 idx,
ZEnt* ent = li->ents + idx;
ent->loc = *loc;
// .. copy filename (needs to be 0-terminated)
// note: Zip paths only have '/' terminators; no need to convert.
char* fn_copy = (char*)malloc(fn_len+1);
if(!fn_copy)
return ERR_NO_MEM;
@ -516,7 +517,7 @@ static int lookup_add_file_cb(const uintptr_t user, const i32 idx,
// initialize lookup data structure for the given Zip archive:
// adds all files to the index.
static int lookup_init(LookupInfo* const li, const void* const file, const size_t size)
static int lookup_init(LookupInfo* li, const void* file, const size_t size)
{
int err;
@ -544,7 +545,7 @@ static int lookup_init(LookupInfo* const li, const void* const file, const size_
// free lookup data structure.
// (no use-after-free checking - that's handled by the VFS)
static int lookup_free(LookupInfo* const li)
static int lookup_free(LookupInfo* li)
{
// free memory allocated for filenames
for(i32 i = 0; i < li->num_files; i++)
@ -563,7 +564,7 @@ static int lookup_free(LookupInfo* const li)
// look up ZLoc, given filename.
static int lookup_get_file_info(LookupInfo* const li, const char* fn, ZLoc* const loc)
static int lookup_get_file_info(LookupInfo* li, const char* fn, ZLoc* loc)
{
// hash (lower case!) filename
char lc_fn[PATH_MAX];
@ -602,7 +603,7 @@ have_idx:
// successively call <cb> for each valid file in the index,
// passing the complete path and <user>.
// if it returns a nonzero value, abort and return that, otherwise 0.
static int lookup_enum_files(LookupInfo* const li, FileCB cb, uintptr_t user)
static int lookup_enum_files(LookupInfo* li, FileCB cb, uintptr_t user)
{
struct stat s;
memset(&s, 0, sizeof(s));
@ -712,7 +713,7 @@ exit_close:
// open and return a handle to the zip archive indicated by <fn>.
// somewhat slow - each file is added to an internal index.
Handle zip_archive_open(const char* const fn)
Handle zip_archive_open(const char* fn)
{
return h_alloc(H_ZArchive, fn);
}
@ -1053,7 +1054,7 @@ static const size_t CHUNK_SIZE = 16*KB;
// begin transferring <size> bytes, starting at <ofs>. get result
// with zip_wait_io; when no longer needed, free via zip_discard_io.
int zip_start_io(ZFile* const zf, off_t user_ofs, size_t max_output_size, void* user_buf, ZipIO* io)
int zip_start_io(ZFile* zf, off_t user_ofs, size_t max_output_size, void* user_buf, ZipIO* io)
{
// not needed, since ZFile tells us the last read offset in the file.
UNUSED(user_ofs);
@ -1289,7 +1290,7 @@ ssize_t zip_read(ZFile* zf, off_t ofs, size_t size, void* p, FileIOCB cb, uintpt
// the mapping will be removed (if still open) when its file is closed.
// however, map/unmap calls should still be paired so that the mapping
// may be removed when no longer needed.
int zip_map(ZFile* const zf, void*& p, size_t& size)
int zip_map(ZFile* zf, void*& p, size_t& size)
{
p = 0;
size = 0;
@ -1325,7 +1326,7 @@ int zip_map(ZFile* const zf, void*& p, size_t& size)
// the mapping will be removed (if still open) when its archive is closed.
// however, map/unmap calls should be paired so that the archive mapping
// may be removed when no longer needed.
int zip_unmap(ZFile* const zf)
int zip_unmap(ZFile* zf)
{
CHECK_ZFILE(zf);

View File

@ -97,7 +97,7 @@ struct ZipIO
// begin transferring <size> bytes, starting at <ofs>. get result
// with zip_wait_io; when no longer needed, free via zip_discard_io.
extern int zip_start_io(ZFile* const zf, off_t ofs, size_t size, void* buf, ZipIO* io);
extern int zip_start_io(ZFile* zf, off_t ofs, size_t size, void* buf, ZipIO* io);
// indicates if the IO referenced by <io> has completed.
// return value: 0 if pending, 1 if complete, < 0 on error.

View File

@ -1,8 +1,8 @@
// path: portable and relative, must add current directory and convert to native
// better to use a cached string from rel_chdir - secure
extern int dir_add_watch(const char* const path, intptr_t* const watch);
extern int dir_add_watch(const char* path, intptr_t* watch);
extern int dir_cancel_watch(const intptr_t watch);
extern int dir_cancel_watch(intptr_t watch);
extern int dir_get_changed_file(char* fn);

View File

@ -129,7 +129,7 @@ int aio_h_set(const int fd, const HANDLE h)
if(fd >= aio_hs_size)
{
const uint size2 = (uint)round_up(fd+8, 8);
HANDLE* const hs2 = (HANDLE*)realloc(aio_hs, size2*sizeof(HANDLE));
HANDLE* hs2 = (HANDLE*)realloc(aio_hs, size2*sizeof(HANDLE));
if(!hs2)
goto fail;
// don't assign directly from realloc -
@ -363,7 +363,7 @@ static int aio_rw(struct aiocb* cb)
const int fd = cb->aio_fildes;
const size_t size = cb->aio_nbytes;
const off_t ofs = cb->aio_offset;
void* const buf = (void*)cb->aio_buf; // from volatile void*
void* buf = (void*)cb->aio_buf; // from volatile void*
assert(buf);
// allocate IO request
@ -500,7 +500,7 @@ fail:
// return status of transfer
int aio_error(const struct aiocb* cb)
{
Req* const r = req_find(cb);
Req* r = req_find(cb);
if(!r)
return -1;
@ -519,7 +519,7 @@ int aio_error(const struct aiocb* cb)
// get bytes transferred. call exactly once for each op.
ssize_t aio_return(struct aiocb* cb)
{
Req* const r = req_find(cb);
Req* r = req_find(cb);
if(!r)
{
debug_warn("aio_return: cb not found (already called aio_return?)");
@ -549,7 +549,7 @@ ssize_t aio_return(struct aiocb* cb)
}
int aio_suspend(const struct aiocb* const cbs[], int n, const struct timespec* ts)
int aio_suspend(const struct aiocb* cbs[], int n, const struct timespec* ts)
{
int i;

View File

@ -57,7 +57,7 @@ extern int aio_error(const struct aiocb*);
extern int aio_fsync(int, struct aiocb*);
extern int aio_read(struct aiocb*);
extern ssize_t aio_return(struct aiocb*);
extern int aio_suspend(const struct aiocb* const[], int, const struct timespec*);
extern int aio_suspend(const struct aiocb* const [], int, const struct timespec*);
extern int aio_write(struct aiocb*);
extern int lio_listio(int, struct aiocb* const[], int, struct sigevent*);

View File

@ -78,7 +78,7 @@ static int get_ver(const char* module, char* out_ver, size_t out_ver_len)
const DWORD ver_size = GetFileVersionInfoSize(module, &unused);
if(!ver_size)
return -1;
void* const buf = malloc(ver_size);
void* buf = malloc(ver_size);
if(!buf)
return ERR_NO_MEM;
@ -189,7 +189,7 @@ int get_monitor_size(int& width_mm, int& height_mm)
// and check for a glBegin export. this requires OpenGL to be initialized,
// though - the DLLs aren't loaded at startup. it'd also be a bit of work
// to sort out MCD, ICD, and opengl32.dll.
static int get_ogl_drv_name(char* const ogl_drv_name, const size_t max_name_len)
static int get_ogl_drv_name(char* ogl_drv_name, const size_t max_name_len)
{
// need single point of exit so that we can close all keys; return this.
int ret = -1;

View File

@ -164,7 +164,7 @@ static int get_packet();
// path: portable and relative, must add current directory and convert to native
// better to use a cached string from rel_chdir - secure
int dir_add_watch(const char* const dir, intptr_t* const _reqnum)
int dir_add_watch(const char* dir, intptr_t* _reqnum)
{
int err = -1;
WIN_SAVE_LAST_ERROR; // Create*
@ -278,7 +278,7 @@ static int extract_events(Watch* w)
// for every packet in buffer: (there's at least one)
for(;;)
{
const FILE_NOTIFY_INFORMATION* const fni = (const FILE_NOTIFY_INFORMATION*)pos;
const FILE_NOTIFY_INFORMATION* fni = (const FILE_NOTIFY_INFORMATION*)pos;
// convert filename from Windows BSTR
// (can't use wcstombs - FileName isn't 0-terminated)

View File

@ -503,7 +503,7 @@ int pthread_mutex_timedlock(pthread_mutex_t* m, const struct timespec* abs_timeo
//////////////////////////////////////////////////////////////////////////////
void* mmap(void* const user_start, const size_t len, const int prot, const int flags, const int fd, const off_t offset)
void* mmap(void* user_start, size_t len, int prot, int flags, int fd, off_t offset)
{
{
WIN_SAVE_LAST_ERROR;
@ -597,7 +597,7 @@ fail:
}
int munmap(void* const start, const size_t len)
int munmap(void* start, size_t len)
{
UNUSED(len);
BOOL ok = UnmapViewOfFile(start);

View File

@ -501,7 +501,7 @@ static int wsdl_init()
// to avoid the OS opening a console on startup (ugly). that means
// stdout isn't associated with a lowio handle; _close ends up
// getting called with fd = -1. oh well, nothing we can do.
FILE* const ret = freopen("stdout.txt", "w", stdout);
FILE* ret = freopen("stdout.txt", "w", stdout);
if(!ret)
debug_warn("stdout freopen failed");
setvbuf(stdout, 0, _IONBF, 0);

View File

@ -124,7 +124,7 @@ CStr g_CursorName = "test";
CStr g_ActiveProfile = "default";
extern int allow_reload();
extern int dir_add_watch(const char* const dir, bool watch_subdirs);
extern int dir_add_watch(const char* dir, bool watch_subdirs);
extern void sle(int);
@ -206,7 +206,7 @@ debug_out("SYS DETECT TIME %g\n\n", t2-t1);
struct utsname un;
uname(&un);
FILE* const f = fopen("../logs/system_info.txt", "w");
FILE* f = fopen("../logs/system_info.txt", "w");
if(!f)
return;
@ -263,6 +263,7 @@ debug_out("SYS DETECT TIME %g\n\n", t2-t1);
fprintf(f, "\nSupported extensions: \n%s\n", SplitExts(exts).c_str());
fclose(f);
f = 0;
}