libjf API reference guide

Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

jf_file.h

Go to the documentation of this file.
00001 /* 00002 * Copyright 2005 Tiian 00003 * {In real life Tiian is Christian Ferrari} 00004 * This file is part of "libjf" package. 00005 * 00006 * "libjf" is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2.1 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * "libjf" is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with ; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 */ 00020 #ifndef JF_FILE_H 00021 #define JF_FILE_H 00022 00023 #include <jf/jf_config.h> 00024 00025 00026 00027 #ifdef HAVE_STDARG_H 00028 # include <stdarg.h> 00029 #endif /* HAVE_STDARG_H */ 00030 00031 #include <jf/jf_defines.h> 00032 #include <jf/jf_utils.h> 00033 #include <jf_journal.h> 00034 00035 00036 00037 /* save old JF_TRACE_MODULE and set a new value */ 00038 #ifdef JF_TRACE_MODULE 00039 # define JF_TRACE_MODULE_SAVE JF_TRACE_MODULE 00040 # undef JF_TRACE_MODULE 00041 #else 00042 # undef JF_TRACE_MODULE_SAVE 00043 #endif /* JF_TRACE_MODULE */ 00044 #define JF_TRACE_MODULE JF_TRACE_MOD_LIB_FILE 00045 00046 00047 00051 #define JF_FILE_OPEN_MODE_SIZE 4 00052 00057 #ifdef _CACHE_STRESS 00058 # define JF_FILE_BUFFER_PAGE_SIZE 4 00059 #else 00060 # define JF_FILE_BUFFER_PAGE_SIZE 4096 00061 #endif /* _CACHE_STRESS */ 00062 00063 00064 00065 #ifdef __cplusplus 00066 extern "C" { 00067 #endif /* __cplusplus */ 00068 00069 00070 00075 struct jf_file_open_opts_s { 00083 int join_the_journal; 00087 struct jf_journal_opts_s journal_opts; 00088 }; 00089 00090 00091 00097 static void inline jf_set_default_file_open_opts( 00098 struct jf_file_open_opts_s *options) { 00099 options->join_the_journal = FALSE; 00100 jf_set_default_journal_opts(&(options->journal_opts)); 00101 } 00102 00103 00104 00109 typedef struct { 00113 jf_journal_t *journal; 00120 int private_journal; 00125 jf_word_t id; 00129 char *char_buffer; 00133 size_t char_buffer_size; 00134 } jf_file_t; 00135 00136 00137 00143 static inline jf_journal_t *jf_file_get_journal(const jf_file_t *jf) { 00144 return jf->journal; 00145 } 00146 00147 00148 00154 static inline jf_word_t jf_file_get_id(const jf_file_t *jf) { 00155 return jf->id; 00156 } 00157 00158 00159 00165 static inline int jf_file_is_safe(const jf_file_t *jf) { 00166 return jf->id != JF_JOURNAL_JOURNAL_FILE_ID && 00167 jf->journal != NULL; 00168 } 00169 00170 00171 00175 void jf_file_reset(jf_file_t *jf); 00176 00177 00178 00228 LIBJF_EXPORT 00229 int jf_file_open(jf_file_t *jfile, jf_journal_t *journal, 00230 const char *path, const char *mode, 00231 const struct jf_file_open_opts_s *options); 00232 00233 00234 00241 LIBJF_EXPORT 00242 int jf_file_close(jf_file_t *jfile); 00243 00244 00245 00255 LIBJF_EXPORT 00256 int jf_file_read(jf_file_t *jf, void *data, 00257 size_t size, size_t *read_number); 00258 00259 00260 00270 LIBJF_EXPORT 00271 int jf_file_write(jf_file_t *jf, const void *data, 00272 size_t size, size_t *write_number); 00273 00274 00275 00284 LIBJF_EXPORT 00285 int jf_file_putc(jf_file_t *jf, int c); 00286 00287 00288 00297 LIBJF_EXPORT 00298 int jf_file_puts(jf_file_t *jf, const char *s); 00299 00300 00301 00310 LIBJF_EXPORT 00311 int jf_file_getc(jf_file_t *jf, int *c); 00312 00313 00314 00327 LIBJF_EXPORT 00328 int jf_file_gets(jf_file_t *jf, size_t size, char *s); 00329 00330 00331 00332 #ifdef HAVE_VSNPRINTF 00333 00345 LIBJF_EXPORT 00346 int jf_file_printf(jf_file_t *jf, size_t *write_number, 00347 const char *format, ...); 00348 00349 00350 00366 LIBJF_EXPORT 00367 int jf_file_vprintf(jf_file_t *jf, size_t *write_number, 00368 const char *format, va_list ap); 00369 #endif /* HAVE_VSNPRINTF */ 00370 00371 00372 00383 static inline int jf_file_eof(const jf_file_t *jfile) 00384 { 00385 jf_journal_t *journal; 00386 jf_word_t file_id; 00387 jf_journal_file_t *jfp; 00388 00389 if (!jf_file_is_safe(jfile)) 00390 return FALSE; 00391 00392 journal = jf_file_get_journal(jfile); 00393 file_id = jf_file_get_id(jfile); 00394 jfp = jf_journal_get_jfile(journal, file_id); 00395 00396 if (jf_journal_file_get_last_uc_pos(jfp) >= 00397 jf_journal_file_get_last_uc_size(jfp)) 00398 return TRUE; 00399 else 00400 return FALSE; 00401 } 00402 00403 00404 00417 LIBJF_EXPORT 00418 int jf_file_seek(jf_file_t *jf, jf_offset_t offset, int whence); 00419 00420 00421 00432 LIBJF_EXPORT 00433 int jf_file_size(jf_file_t *jf, jf_offset_t *last_size, 00434 jf_offset_t *last_uc_size); 00435 00436 00437 00445 static inline int jf_file_rewind(jf_file_t *jf) { 00446 return jf_file_seek(jf, (jf_offset_t)0, SEEK_SET); } 00447 00448 00449 00458 LIBJF_EXPORT 00459 jf_offset_t jf_file_get_cache_limit(const jf_file_t *jfile); 00460 00461 00462 00471 static inline int jf_file_commit(jf_file_t *jfile) { 00472 return jf_journal_commit_int( 00473 jf_file_get_journal(jfile), jf_file_get_id(jfile)); 00474 } 00475 00476 00477 00486 static inline int jf_file_rollback(jf_file_t *jfile) { 00487 return jf_journal_rollback_int( 00488 jf_file_get_journal(jfile), jf_file_get_id(jfile)); 00489 } 00490 00491 00492 00493 00504 int jf_file_check_mode(const char *mode, uint32_t *flags); 00505 00506 00507 00530 int jf_file_build_open_mode(uint32_t flags, char *mode1, char *mode2, 00531 int *repos, int *resize, int *append); 00532 00533 00534 00535 #ifdef __cplusplus 00536 } 00537 #endif /* __cplusplus */ 00538 00539 00540 00541 /* restore old value of JF_TRACE_MODULE */ 00542 #ifdef JF_TRACE_MODULE_SAVE 00543 # undef JF_TRACE_MODULE 00544 # define JF_TRACE_MODULE JF_TRACE_MODULE_SAVE 00545 # undef JF_TRACE_MODULE_SAVE 00546 #endif /* JF_TRACE_MODULE_SAVE */ 00547 00548 00549 00550 #endif /* JF_FILE_H */ 00551

Copyright 2005 © Tiian