Talk:VFS
Revision as of 07:22, 27 March 2007 by Argent Stonecutter (talk | contribs)
This is a talk page associated with the Open Source Portal. Changes to all pages like this one can be tracked by watching the "Related Changes" for "Category:Open Source Talk Page"
Please sign comments you leave here by putting four tildes (~~~~) at the end of your comment. For more guidelines, see Talk Page Guidelines
Please sign comments you leave here by putting four tildes (~~~~) at the end of your comment. For more guidelines, see Talk Page Guidelines
See also: OpenClient: Cache operation discussion
Alternative implementation
Only desk-checked:
// N_LEVELS * N_CHARS should probably not be greater than 8, since there's a // separator in the UUID there. #define N_LEVELS 2 // UUID is hex, so 2 chars means maximum of 256 directories per level #define N_CHARS 2 #ifdef I_KNOW_THIS_ITS_A_UNIX_SYSTEM # define DIR_SEP '/' #else # define DIR_SEP '\\' #endif extern char *cache_dir; extern int safe_make_directory_path(char *path); FILE *fopen_texture(char *filename, char *mode) { int l = strlen(cache_dir); int m = strlen(filename); char *new_filename = calloc(l + 1 + m + N_LEVELS * (N_CHARS + 1) + 1); char *s, *t; int i, j; if (!new_filename) return NULL; s = filename; t = new_filename; strcpy(t, cache_dir); t += l; for (i = 0; *s && i < N_LEVELS; i++) { *t++ = DIR_SEP; for (j = 0; *s && j < N_CHARS; j++) *t++ = *s++; } *t = '\0'; if (!safe_make_directory_path(new_filename)) return NULL; *t++ = DIR_SEP; strcpy(t, filename); return fopen(new_filename, mode); }