Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
glibc/string/tst-svc.c
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
48 lines (35 sloc)
849 Bytes
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
/* Test for strverscmp() */ | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#define MAX_STRINGS 256 | |
#define MAX_LINE_SIZE 32 | |
static int | |
compare (const void *p1, const void *p2) | |
{ | |
return strverscmp (*((char **) p1), *((char **) p2)); | |
} | |
static int | |
do_test (void) | |
{ | |
char line[MAX_LINE_SIZE + 1]; | |
char *str[MAX_STRINGS]; | |
int count = 0; | |
int i, n; | |
while (count < MAX_STRINGS && fgets (line, MAX_LINE_SIZE, stdin) != NULL) | |
{ | |
n = strlen (line) - 1; | |
if (line[n] == '\n') | |
line[n] = '\0'; | |
str[count] = strdup (line); | |
if (str[count] == NULL) | |
exit (EXIT_FAILURE); | |
++count; | |
} | |
qsort (str, count, sizeof (char *), compare); | |
for (i = 0; i < count; ++i) | |
puts (str[i]); | |
return EXIT_SUCCESS; | |
} | |
#define TEST_FUNCTION do_test () | |
#include "../test-skeleton.c" |