return ret;
}
-FILE *
+void
xfreopen (const char *path, const char *mode, FILE *stream)
{
FILE *ret;
path, strerror (errno));
exit (1);
}
-
- return ret;
}
char *
{
char *ret;
+ if (s == NULL)
+ return NULL;
+
ret = strdup (s);
if (ret == NULL) {
}
}
+ttt_status_t
+xconnect (int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen)
+{
+ int ret;
+
+ ret = connect (sockfd, serv_addr, addrlen);
+ if (ret == -1) {
+ switch (errno) {
+ case ECONNREFUSED:
+ return TTT_STATUS_CONNECTION_REFUSED;
+ case EHOSTUNREACH:
+ case ENETUNREACH:
+ return TTT_STATUS_NETWORK_UNREACHABLE;
+ default:
+ fprintf (stderr, "Error: connect failed (errno = %d): %s. Aborting.\n",
+ errno, strerror (errno));
+ exit (1);
+ }
+ }
+
+ return TTT_STATUS_SUCCESS;
+}
+
void
xlisten (int s, int backlog)
{
return ret;
}
+
+ssize_t
+xread (int fd, void *buf, size_t count)
+{
+ int ret;
+
+ ret = read (fd, buf, count);
+ if (ret == -1) {
+ fprintf (stderr, "Error: read failed: %s. Aborting.\n",
+ strerror (errno));
+ exit (1);
+ }
+
+ return ret;
+}
+
+ssize_t
+xwrite (int fd, const void *buf, size_t count)
+{
+ int ret;
+
+ ret = write (fd, buf, count);
+ if (ret == -1) {
+ fprintf (stderr, "Error: write failed: %s. Aborting.\n",
+ strerror (errno));
+ exit (1);
+ }
+
+ return ret;
+}