Add Apache License version 2.0.
[pbc.git] / pbc / pbc_getline.c
blobdc44cc40cca81a3bbbd8bf8519d633f8c0028b43
1 #include <stdio.h>
2 #include <string.h>
4 #include "pbc_memory.h"
6 char *pbc_getline(const char *prompt) {
7 char s[1024];
8 if (prompt) fputs(prompt, stdout);
9 if (!fgets(s, 1024, stdin)) return NULL;
10 if (feof(stdin)) return NULL;
11 /* use strdup rather than pbc_strdup. because
12 * 1. readline version of this function uses malloc.
13 * 2. pbc_malloc called by pbc_strdup may differ from malloc.
14 * here we keep consistency.
16 return strdup(s);