Changes in help.c [0fbda193:c227706]
Legend:
- Unmodified
- Added
- Removed
-
help.c
r0fbda193 rc227706 71 71 { 72 72 /* FIXME: Clean up */ 73 help_free( help ); 73 // help_close( *help ); 74 *help = NULL; 74 75 g_free( s ); 75 return NULL;76 return( NULL ); 76 77 } 77 78 i = strchr( s, '\n' ) - s; 78 79 79 if( h-> title)80 if( h->string ) 80 81 { 81 82 h = h->next = g_new0( help_t, 1 ); 82 83 } 83 h-> title= g_new ( char, i );84 h->string = g_new ( char, i ); 84 85 85 strncpy( h-> title, s + 1, i - 1 );86 h-> title[i-1] = 0;86 strncpy( h->string, s + 1, i - 1 ); 87 h->string[i-1] = 0; 87 88 h->fd = (*help)->fd; 88 89 h->offset.file_offset = lseek( h->fd, 0, SEEK_CUR ) - buflen + i + 1; … … 102 103 } 103 104 104 void help_free( help_t **help ) 105 { 106 help_t *h, *oh; 107 int last_fd = -1; /* Weak de-dupe */ 108 109 if( help == NULL || *help == NULL ) 110 return; 111 112 h = *help; 113 while( h ) 114 { 115 if( h->fd != last_fd ) 116 { 117 close( h->fd ); 118 last_fd = h->fd; 119 } 120 g_free( h->title ); 121 h = (oh=h)->next; 122 g_free( oh ); 123 } 124 125 *help = NULL; 126 } 127 128 char *help_get( help_t **help, char *title ) 105 char *help_get( help_t **help, char *string ) 129 106 { 130 107 time_t mtime; … … 134 111 for( h = *help; h; h = h->next ) 135 112 { 136 if( h->title != NULL && g_strcasecmp( h->title, title ) == 0 ) 113 if( h->string != NULL && 114 g_strcasecmp( h->string, string ) == 0 ) 137 115 break; 138 116 } … … 141 119 char *s = g_new( char, h->length + 1 ); 142 120 121 if( fstat( h->fd, stat ) != 0 ) 122 { 123 g_free( h ); 124 *help = NULL; 125 return NULL; 126 } 127 mtime = stat->st_mtime; 128 129 if( mtime > h->mtime ) 130 return NULL; 131 143 132 s[h->length] = 0; 144 133 if( h->fd >= 0 ) 145 134 { 146 if( fstat( h->fd, stat ) != 0 )147 {148 g_free( s );149 return NULL;150 }151 mtime = stat->st_mtime;152 153 if( mtime > h->mtime )154 {155 g_free( s );156 return NULL;157 }158 159 135 lseek( h->fd, h->offset.file_offset, SEEK_SET ); 160 136 read( h->fd, s, h->length );
Note: See TracChangeset
for help on using the changeset viewer.