2024-01-13 22:18:21 +00:00
|
|
|
#ifndef _GET_STRING_H
|
|
|
|
#define _GET_STRING_H
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
int mu_get_string(const char *prog_name, char *buf, const size_t len) {
|
|
|
|
off_t rbytes = read(STDIN_FILENO, buf, len);
|
|
|
|
|
|
|
|
if (rbytes <= 0) {
|
|
|
|
fprintf(stderr, "%s: %s\n", prog_name, strerror(errno));
|
2024-01-14 08:38:55 +00:00
|
|
|
return 0;
|
2024-01-13 22:18:21 +00:00
|
|
|
}
|
|
|
|
|
2024-01-15 19:26:18 +00:00
|
|
|
if (rbytes > 0)
|
2024-01-13 22:18:21 +00:00
|
|
|
buf[rbytes - 1] = '\0';
|
|
|
|
|
2024-01-15 19:26:18 +00:00
|
|
|
buf[rbytes] = '\0';
|
2024-01-14 08:38:55 +00:00
|
|
|
return rbytes;
|
2024-01-13 22:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|