File tree Expand file tree Collapse file tree 2 files changed +7
-47
lines changed Expand file tree Collapse file tree 2 files changed +7
-47
lines changed Original file line number Diff line number Diff line change @@ -638,28 +638,12 @@ int commonio_open (struct commonio_db *db, int mode)
638
638
return 0 ;
639
639
}
640
640
641
- buflen = BUFLEN ;
642
- buf = MALLOC (buflen , char );
643
- if (NULL == buf )
644
- goto cleanup_errno ;
645
-
646
- while (fgets (buf , buflen , db -> fp ) != NULL ) {
641
+ buf = NULL ;
642
+ while (getline (& buf , & buflen , db -> fp ) != -1 ) {
647
643
struct commonio_entry * p ;
648
644
649
- while ( (strrchr (buf , '\n' ) == NULL )
650
- && (feof (db -> fp ) == 0 )) {
651
- size_t len ;
652
-
653
- buflen += BUFLEN ;
654
- buf = REALLOCF (buf , buflen , char );
655
- if (NULL == buf )
656
- goto cleanup_errno ;
657
-
658
- len = strlen (buf );
659
- if (fgets (buf + len , buflen - len , db -> fp ) == NULL )
660
- goto cleanup_buf ;
661
- }
662
- stpsep (buf , "\n" );
645
+ if (stpsep (buf , "\n" ) == NULL )
646
+ goto cleanup_buf ;
663
647
664
648
line = strdup (buf );
665
649
if (NULL == line ) {
Original file line number Diff line number Diff line change @@ -141,39 +141,15 @@ void endsgent (void)
141
141
static size_t buflen = 0 ;
142
142
static char * buf = NULL ;
143
143
144
- char * cp ;
145
-
146
- if (0 == buflen ) {
147
- buf = MALLOC (BUFSIZ , char );
148
- if (NULL == buf ) {
149
- return NULL ;
150
- }
151
- buflen = BUFSIZ ;
152
- }
153
-
154
144
if (NULL == fp ) {
155
145
return NULL ;
156
146
}
157
147
158
- if (fgets (buf , buflen , fp ) == NULL )
148
+ if (getline (& buf , & buflen , fp ) == -1 )
149
+ return NULL ;
150
+ if (stpsep (buf , "\n" ) == NULL )
159
151
return NULL ;
160
152
161
- while ( (strrchr (buf , '\n' ) == NULL )
162
- && (feof (fp ) == 0 )) {
163
- size_t len ;
164
-
165
- cp = REALLOC (buf , buflen * 2 , char );
166
- if (NULL == cp ) {
167
- return NULL ;
168
- }
169
- buf = cp ;
170
- buflen *= 2 ;
171
-
172
- len = strlen (buf );
173
- if (fgets (& buf [len ], buflen - len , fp ) == NULL )
174
- return NULL ;
175
- }
176
- stpsep (buf , "\n" );
177
153
return (sgetsgent (buf ));
178
154
}
179
155
You can’t perform that action at this time.
0 commit comments