head 1.4; access; symbols PETIDOMO_4_0b6:1.4 PETIDOMO_4_0b5:1.4 PETIDOMO_4_0b4:1.4 PETIDOMO_4_0b3:1.4 BEFORETHL:1.4 petidomo-2-2:1.1.1.1 petidomo:1.1.1; locks; strict; comment @ * @; 1.4 date 2001.01.19.14.56.33; author rse; state Exp; branches; next 1.3; 1.3 date 2001.01.18.20.30.50; author rse; state Exp; branches; next 1.2; 1.2 date 2000.12.13.15.35.14; author simons; state Exp; branches; next 1.1; 1.1 date 2000.12.13.13.19.23; author simons; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2000.12.13.13.19.23; author simons; state Exp; branches; next ; desc @@ 1.4 log @Get rid of all complaints from GCC 2.97 (except for two things which I do not want to change on my own) @ text @/* $Source: /e/ossp/cvs/ossp-pkg/petidomo/io.c,v $ $Revision: 1.3 $ Copyright (C) 2000 by CyberSolutions GmbH, Germany. This file is part of Petidomo. Petidomo is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. Petidomo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ #include #include #include #include #include "petidomo.h" char * LoadFromDescriptor(int fd) { char * buffer; unsigned int buffer_size; unsigned int read_size; ssize_t rc; buffer_size = 8 * 1024; read_size = 0; buffer = malloc(buffer_size); if (buffer == NULL) { syslog(LOG_ERR, "Failed to allocate %u byte of memory.", buffer_size); return NULL; } for (;;) { rc = read(fd, (buffer+read_size), (buffer_size - read_size - 1)); if (rc == -1) { syslog(LOG_ERR, "Error occured while reading file: %s", strerror(errno)); free(buffer); return NULL; } else if (rc == 0) { /* EOF */ break; } else { /* Read succeeded normally */ read_size += rc; if ((buffer_size - read_size) <= 1) { /* re-allocate larger buffer */ char * new_buffer; buffer_size += 4 * 1024; new_buffer = realloc(buffer, buffer_size); if (new_buffer == NULL) { syslog(LOG_ERR, "Failed to allocate %u byte of memory.", buffer_size); free(buffer); return NULL; } else buffer = new_buffer; } } } buffer[read_size] = '\0'; /* terminate read data */ errno = read_size; return buffer; } char * loadfile(const char * filename) { struct flock lock; char * buffer; int fd; int len; int rc; assert(filename); if ((fd = open(filename, O_RDONLY, 0)) == -1) { syslog(LOG_WARNING, "open(\"%s\", O_RDONLY): %s", filename, strerror(errno)); return NULL; } lock.l_start = 0; lock.l_len = 0; lock.l_type = F_RDLCK; lock.l_whence = SEEK_SET; fcntl(fd, F_SETLKW, &lock); if ((len = lseek(fd, 0, SEEK_END)) == -1) { syslog(LOG_WARNING, "lseek(\"%s\", SEEK_END): %s", filename, strerror(errno)); return NULL; } if ((lseek(fd, 0, SEEK_SET) == -1)) { syslog(LOG_WARNING, "lseek(\"%s\", SEEK_SET): %s", filename, strerror(errno)); return NULL; } buffer = malloc(len+1); if (buffer == NULL) { syslog(LOG_WARNING, "Failed to allocate %d byte of memory.", len+1); return NULL; } rc = read(fd, buffer, len); if (rc != len) { syslog(LOG_WARNING, "read(\"%s\", %d) read %d byte: %s", filename, len, rc, strerror(errno)); return NULL; } buffer[len] = '\0'; close(fd); errno = len; return buffer; } int savefile(const char * filename, const char * buffer) { struct flock lock; int fd, len; ssize_t rc; assert(filename && buffer); len = strlen(buffer); fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); lock.l_start = 0; lock.l_len = 0; lock.l_type = F_WRLCK; lock.l_whence = SEEK_SET; fcntl(fd, F_SETLKW, &lock); if (fd == -1) { syslog(LOG_ERR, "open(\"%s\"): %s", filename, strerror(errno)); return -1; } rc = write(fd, buffer, len); if (rc == -1) { syslog(LOG_ERR, "Error occured while writing to file \"%s\": %s", filename, strerror(errno)); close(fd); return -1; } close(fd); return 0; } @ 1.3 log @As we agreed today, Petidomo is now open because licensed under GPL and always will be licensed under GPL, so use "Petidomo" as the program name everywhere and consistently. @ text @d3 1 a3 1 $Revision: 1.2 $ d23 1 d46 1 a46 1 syslog(LOG_ERR, "Error occured while reading file: %m"); d87 1 a87 1 syslog(LOG_WARNING, "open(\"%s\", O_RDONLY): %m", filename); d96 1 a96 1 syslog(LOG_WARNING, "lseek(\"%s\", SEEK_END): %m", filename); d100 1 a100 1 syslog(LOG_WARNING, "lseek(\"%s\", SEEK_SET): %m", filename); d110 1 a110 1 syslog(LOG_WARNING, "read(\"%s\", %d) read %d byte: %m", filename, len, rc); d137 1 a137 1 syslog(LOG_ERR, "open(\"%s\"): %m", filename); d142 1 a142 1 syslog(LOG_ERR, "Error occured while writing to file \"%s\": %m", filename); @ 1.2 log @ - Added correct GNU GPL copyright statements to the files. - Removed unnecessary include statements. @ text @d2 2 a3 2 $Source$ $Revision$ d7 1 a7 1 This file is part of OpenPetidomo. d9 1 a9 1 OpenPetidomo is free software; you can redistribute it and/or modify d14 1 a14 1 OpenPetidomo is distributed in the hope that it will be useful, but @ 1.1 log @Initial revision @ text @d2 17 a18 7 * $Source: /usr/local/libdata/cvs/simons/petidomo/src/petidomo/io.c,v $ * $Revision: 1.3 $ * $Date: 1997/11/29 14:43:40 $ * * Copyright (C) 1997 by CyberSolutions GmbH. * All rights reserved. */ d24 1 a24 1 #include @ 1.1.1.1 log @Imported Petidomo 2.2 as found on www.petidomo.com. @ text @@