Mercurial > hg > Game > Cerium
changeset 1997:48419ad1ade5 draft
add read() error check in
author | masa |
---|---|
date | Mon, 21 Apr 2014 19:54:45 +0900 |
parents | 9657434c21a4 |
children | ed30952c240e |
files | example/word_count/main.cc |
diffstat | 1 files changed, 6 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/example/word_count/main.cc Mon Apr 21 18:49:21 2014 +0900 +++ b/example/word_count/main.cc Mon Apr 21 19:54:45 2014 +0900 @@ -49,21 +49,20 @@ static void my_read(char *filename, WordCount *w, TaskManager *manager) { - /*マッピングだよ!*/ - struct stat sb; long fd = w->fd; if ((fd=open(filename,O_RDONLY,0666))==0) { fprintf(stderr,"can't open %s\n",filename); } - if (fstat(fd,&sb)) { - fprintf(stderr,"can't fstat %s\n",filename); - } - //madvise(w->file_mmap, w->read_filesize, POSIX_MADV_NORMAL); w->file_mmap = (char*)manager->allocate(w->read_filesize); - read(fd, w->file_mmap, w->read_filesize); + int read_check = read(fd, w->file_mmap, (long)w->read_filesize); + if (read_check == -1) { + fprintf(stderr,"Can't Read file\n"); + perror(NULL); + exit(0); + } if (w->file_mmap == (caddr_t)-1) { fprintf(stderr,"Can't mmap file\n");