/* *libproc * *common utilities needed to process /proc. * *A library interface for finding process information from /proc. *This is also an interface into various things which haven't yet been integrated into sysfs, * as appropriate. Copyright (C) 2004 Joseph Pingenot This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #define BUFFLEN 3 int main(void) { int fd; char* file; int buffread; char buff[BUFFLEN]; int buffpoint; //file = "/proc/acpi/battery/BAT0/info"; file = "test-openfile.c"; /*Alright. Now we open up the info file for reading.*/ if((fd = open(file, O_RDONLY)) < 0){ /*Open failed. return.*/ return -1; } while(1) { printf("*WHILE: buffread=%d, BUFFLEN=%d, fd=%d\n", buffread, BUFFLEN, fd); buffread = read(fd, buff, BUFFLEN); printf("*WHILE: buffread=%d, BUFFLEN=%d, fd=%d\n", buffread, BUFFLEN, fd); printf(" errno=%d\n", errno); if(buffread <= 0) break; /*Now walk through buff, copying until we hit a colon*/ printf("buff='"); for(buffpoint = 0; buffpoint < buffread; buffpoint++){ printf("%c", buff[buffpoint]); } printf("'\n"); } return 0; }