00001 00002 /* 00003 ** Copyright (C) 2002 Russell Leighton 00004 ** 00005 ** This program is free software; you can redistribute it and/or modify 00006 ** it under the terms of the GNU General Public License as published by 00007 ** the Free Software Foundation; either version 2 of the License, or 00008 ** (at your option) any later version. 00009 ** 00010 ** This program is distributed in the hope that it will be useful, 00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 ** GNU General Public License for more details. 00014 ** 00015 ** You should have received a copy of the GNU General Public License 00016 ** along with this program; if not, write to the Free Software 00017 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00020 00021 #ifndef __AW_SYSINFO_H__ 00022 #define __AW_SYSINFO_H__ 00023 00033 /* -------- os ports --------- */ 00034 00035 /* -------- generic --------- */ 00036 00037 /* This macro opens FILE and reads the current 00038 contents of the file into the specified buf 00039 and closes file. Replaces string nulls 00040 with ' ' except for last one. 00041 */ 00042 #define PROC_FILE_TO_BUF(buf, bufsize, FILE, logger) { \ 00043 int32_t i, n, fd; \ 00044 if ( (fd = open(FILE, O_RDONLY)) == -1) { \ 00045 aw_log(logger, AW_ERROR_LOG_LEVEL, "Cannot open %s: %s",\ 00046 FILE, strerror(errno)); \ 00047 n=0; \ 00048 goto _done_f2b; \ 00049 } \ 00050 if ((n = read(fd, buf, bufsize - 1)) < 0) { \ 00051 aw_log(logger, AW_ERROR_LOG_LEVEL, "Cannot read %s: %s",\ 00052 FILE, strerror(errno)); \ 00053 n=0; \ 00054 goto _done_f2b; \ 00055 } \ 00056 _done_f2b:; \ 00057 buf[n] = '\0'; \ 00058 /* in case file has more than 1 string nulls */ \ 00059 for(i=0; i<n; i++) { if ( buf[i] == '\0' ) buf[i] = ' ' ; } \ 00060 close(fd); \ 00061 } 00062 00063 00064 #endif