int util_proc_mem_free(void) { FILE *stream = util_fopen("/proc/meminfo" , "r"); int mem; util_fskip_lines(stream , 1); util_fskip_token(stream); util_fscanf_int(stream , &mem); fclose(stream); return mem; }
bool ecl_kw_grdecl_fseek_next_kw( FILE * stream ) { long start_pos = util_ftell( stream ); long current_pos; char next_kw[256]; /* Determine if the current position of the file pointer is at the beginning of the line; if not skip the rest of the line; this is applies even though the tokens leading up this are not comments. */ { while (true) { char c; if (util_ftell(stream) == 0) /* We are at the very beginning of the file. Can just jump out of the loop. */ break; util_fseek( stream , -1 , SEEK_CUR ); c = fgetc( stream ); if (c == '\n') { /* We have walked backwards reaching the start of the line. We have not reached any !isspace() characters on the way and can go back to start_pos and read from there. */ util_fseek( stream , start_pos , SEEK_SET ); break; } if (!isspace( c )) { /* We hit a non-whitespace character; this means that start_pos was not at the start of the line. We skip the rest of this line, and then start reading on the next line. */ util_fskip_lines( stream , 1 ); break; } util_fseek( stream , -2 , SEEK_CUR ); } } while (true) { current_pos = util_ftell( stream ); if (fscanf(stream , "%s" , next_kw) == 1) { if ((next_kw[0] == next_kw[1]) && (next_kw[0] == ECL_COMMENT_CHAR)) // This is a comment line - skip it. util_fskip_lines( stream , 1 ); else { // This is a valid keyword i.e. a non-commented out string; return true. util_fseek( stream , current_pos , SEEK_SET ); return true; } } else { // EOF reached - return False. util_fseek( stream , start_pos , SEEK_SET ); return false; } } }