Changeset 3127


Ignore:
Timestamp:
May 28, 2013, 6:54:03 AM (6 years ago)
Author:
bruno
Message:
  • Backport mr_getline from branch 3.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/mondo/src/lib/mr_mem.c

    r2381 r3127  
    5353}
    5454
    55 /* encapsulation function for getline */
    56 void mr_getline_int(char **lineptr, size_t *n, FILE *fd, int line, const char *file) {
    57    
    58     ssize_t ret;
    59 
    60     ret = getline(lineptr,n,fd);
    61     if ((ret == -1) && (! feof(fd))) {
    62         mr_msg_int(1,line,file,"Unable to alloc memory in mr_getline\nExiting...");
    63         mr_exit(-1,"Unable to alloc memory in mr_getline");
    64     }
    65 }
    66 
    6755/* encapsulation function for asprintf */
    6856void mr_asprintf_int(char **strp, int line, const char *file, const char *fmt, ...) {
     
    7866    }
    7967    va_end(args);
     68}
     69
     70/* encapsulation function for getline */
     71void mr_getline_int(char **lineptr, FILE *fd, int line, const char *file) {
     72   
     73    ssize_t ret;
     74    size_t n = 0;
     75
     76    ret = getline(lineptr,&n,fd);
     77    if ((ret == -1) && (! feof(fd))) {
     78        mr_msg_int(1,line,file,"Unable to alloc memory in mr_getline\nExiting...");
     79        mr_exit(-1,"Unable to alloc memory in mr_getline");
     80    }
     81    /*  We reached end of file, allocating empty string */
     82    if (ret == -1) {
     83        mr_asprintf_int(lineptr, line, file, "");
     84    }
    8085}
    8186
Note: See TracChangeset for help on using the changeset viewer.