All pastes #716512 Raw Edit

Untitled

public c v1 · immutable
#716512 ·published 2007-09-26 22:00 UTC
rendered paste body
intparse_file ( int pf_file, char ** lines ){  FILE *    stream ;  int       nlines ;  int       i ;  char **   files     = ( char ** ) malloc ( sizeof ( char * ) * 4 ) ;  char *    line      = ( char * ) malloc ( sizeof ( char ) * 1000 ) ;  for ( i=0; i<4; i++ )    files[i] = ( char * ) malloc ( sizeof ( char ) * 50 ) ;  strncpy ( files[0], "/home/kik/test/etc/portage/package.keywords",  50 ) ;  strncpy ( files[1], "/home/kik/test/etc/portage/package.use",       50 ) ;  strncpy ( files[2], "/home/kik/test/etc/portage/package.mask",      50 ) ;  strncpy ( files[3], "/home/kik/test/etc/portage/package.unmask",    50 ) ;  if ( ! ( nlines = count_lines ( files[pf_file] ) ) )    ask_create_file ( files[pf_file] ) ;  if ( ! ( stream = fopen ( files[pf_file], "r" ) ) )    return 1 ;  init_string ( line ) ;  lines = ( char ** ) malloc ( sizeof ( char * ) * nlines ) ;  /* populate the lines array with lines from the file */  i = 0 ;  while ( fgets( line, 1000, stream ) ){    i++ ;    if ( ! has_newline ( line ) && i != nlines ) /* the line is bigger than 1000 characters and has been cut */      return 1 ;    lines[i] = ( char * ) malloc ( sizeof ( char ) * strlen ( line ) ) ;    strcpy ( lines[i], line ) ;  }  free ( line ) ;  return 0 ;}