-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix usage of 'getline' function from standard library (Github issue #2)
when getline() is inlined by the compiler, it resorts to using and linking against the __getdelim function from the standard library. However only the getdelim function was covered by pdwfs, not the __getdelim Besides no tests were actually covering getline and getdelim...bad, very bad.
- Loading branch information
Showing
5 changed files
with
73 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2019 CEA | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#define _GNU_SOURCE | ||
#include <unistd.h> | ||
#include <assert.h> | ||
#include "tests.h" | ||
|
||
int test_getline_getdelim() { | ||
|
||
int n = 0; | ||
|
||
FILE* f = fopen(TESTFILE, "w"); | ||
CHECK_NULL(f, "fopen") | ||
|
||
n = fprintf(f, "Hello World !\n"); | ||
CHECK_ERROR(n, "fprintf") | ||
n = fprintf(f, "Hello Go !\n"); | ||
CHECK_ERROR(n, "fprintf") | ||
|
||
fclose(f); | ||
|
||
f = fopen(TESTFILE, "r"); | ||
CHECK_NULL(f, "fopen") | ||
|
||
char * line = NULL; | ||
size_t len = 0; | ||
ssize_t read = 0; | ||
|
||
read = getline(&line, &len, f); | ||
CHECK_ERROR(read, "getline") | ||
|
||
assert(strncmp(line, "Hello World !\n", 14) == 0); | ||
|
||
read = getdelim(&line, &len, '\n', f); | ||
CHECK_ERROR(read, "getdelim") | ||
|
||
assert(strncmp(line, "Hello Go !\n", 11) == 0); | ||
|
||
free(line); | ||
fclose(f); | ||
unlink(TESTFILE); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters