/[svn]/ircd-hybrid/trunk/src/conf_db.c
ViewVC logotype

Diff of /ircd-hybrid/trunk/src/conf_db.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1625 by michael, Thu Nov 1 13:49:25 2012 UTC revision 1626 by michael, Thu Nov 1 17:21:59 2012 UTC
# Line 177  open_db_write(const char *service, const Line 177  open_db_write(const char *service, const
177    unlink(filename);    unlink(filename);
178    
179    /* Use open() to avoid people sneaking a new file in under us */    /* Use open() to avoid people sneaking a new file in under us */
180    fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0666);    if ((fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0666)) >= 0)
181    f->fp = fdopen(fd, "wb");   /* will fail and return NULL if fd < 0 */      f->fp = fdopen(fd, "wb");
182    
183    if (!f->fp || !write_file_version(f, version))    if (!f->fp || !write_file_version(f, version))
184    {    {
# Line 332  close_db(struct dbFILE *f) Line 332  close_db(struct dbFILE *f)
332   * and read pointers are returned as either (void *)0 or (void *)1.  A   * and read pointers are returned as either (void *)0 or (void *)1.  A
333   * string is stored with a 2-byte unsigned length (including the trailing   * string is stored with a 2-byte unsigned length (including the trailing
334   * \0) first; a length of 0 indicates that the string pointer is NULL.   * \0) first; a length of 0 indicates that the string pointer is NULL.
335   * Written strings are truncated silently at 65534 bytes, and are always   * Written strings are truncated silently at 4294967294 bytes, and are always
336   * null-terminated.   * null-terminated.
337   */   */
338    
# Line 545  int Line 545  int
545  read_string(char **ret, struct dbFILE *f)  read_string(char **ret, struct dbFILE *f)
546  {  {
547    char *s = NULL;    char *s = NULL;
548    uint16_t len = 0;    uint32_t len = 0;
549    
550    if (read_uint16(&len, f) < 0)    if (read_uint32(&len, f) < 0)
551      return -1;      return -1;
552    
553    if (len == 0)    if (len == 0)
# Line 580  write_string(const char *s, struct dbFIL Line 580  write_string(const char *s, struct dbFIL
580    uint32_t len = 0;    uint32_t len = 0;
581    
582    if (!s)    if (!s)
583      return write_uint16(0, f);      return write_uint32(0, f);
584    
585    len = strlen(s);    len = strlen(s);
586    
587    if (len > 65534)    if (len > 4294967294)
588      len = 65534;      len = 4294967294;
589    if (write_uint16((uint16_t)(len + 1), f) < 0)    if (write_uint32(len + 1, f) < 0)
590      return -1;      return -1;
591    if (len > 0 && fwrite(s, 1, len, f->fp) != len)    if (len > 0 && fwrite(s, 1, len, f->fp) != len)
592      return -1;      return -1;

Legend:
Removed from v.1625  
changed lines
  Added in v.1626

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28