kinetic-c  v0.12.0
Seagate Kinetic Protocol Client Library for C
syscall.c
Go to the documentation of this file.
1 /*
2 * kinetic-c
3 * Copyright (C) 2015 Seagate Technology.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20 #include "syscall.h"
21 
22 #include <unistd.h>
23 #include <fcntl.h>
24 #include <pthread.h>
25 
26 /* Wrappers for syscalls, to allow mocking for testing. */
27 int syscall_poll(struct pollfd fds[], nfds_t nfds, int timeout) {
28  return poll(fds, nfds, timeout);
29 }
30 
31 int syscall_close(int fd) {
32  return close(fd);
33 }
34 
35 ssize_t syscall_write(int fildes, const void *buf, size_t nbyte) {
36  return write(fildes, buf, nbyte);
37 }
38 
39 ssize_t syscall_read(int fildes, void *buf, size_t nbyte) {
40  return read(fildes, buf, nbyte);
41 }
42 
43 /* Wrappers for OpenSSL calls. */
44 int syscall_SSL_write(SSL *ssl, const void *buf, int num) {
45  return SSL_write(ssl, buf, num);
46 }
47 
48 int syscall_SSL_read(SSL *ssl, void *buf, int num) {
49  return SSL_read(ssl, buf, num);
50 }
51 
52 int syscall_SSL_get_error(const SSL *ssl, int ret) {
53  return SSL_get_error(ssl, ret);
54 }
55 
56 
57 /* Wrapper for gettimeofday and (where available)
58  * clock_gettime(CLOCK_MONOTONIC), which is used when
59  * RELATIVE is true. */
60 int syscall_timestamp(struct timeval *restrict tv, bool relative) {
61 #if 0
62  if (relative) {
63  struct timespec ts;
64  if (0 != clock_gettime(CLOCK_MONOTONIC, &ts)) {
65  return -1;
66  }
67  tv->tv_sec = ts.tv_sec;
68  tv->tv_usec = ts.tv_nsec / 1000L;
69  return 0;
70  }
71 #else
72  (void)relative;
73 #endif
74  return gettimeofday(tv, NULL);
75 }
76 
77 int syscall_pthread_join(pthread_t thread, void **value_ptr)
78 {
79  return pthread_join(thread, value_ptr);
80 }
int syscall_SSL_get_error(const SSL *ssl, int ret)
Definition: syscall.c:52
struct pollfd fds[1000+1]
Tracked file descriptors, for polling.
int syscall_close(int fd)
Definition: syscall.c:31
int syscall_timestamp(struct timeval *restrict tv, bool relative)
Wrapper for gettimeofday and (where available) clock_gettime(CLOCK_MONOTONIC), which is used when REL...
Definition: syscall.c:60
ssize_t syscall_read(int fildes, void *buf, size_t nbyte)
Definition: syscall.c:39
int syscall_pthread_join(pthread_t thread, void **value_ptr)
Wrapper for pthread calls.
Definition: syscall.c:77
int syscall_SSL_read(SSL *ssl, void *buf, int num)
Definition: syscall.c:48
int syscall_SSL_write(SSL *ssl, const void *buf, int num)
Wrappers for OpenSSL calls.
Definition: syscall.c:44
ssize_t syscall_write(int fildes, const void *buf, size_t nbyte)
Definition: syscall.c:35
int syscall_poll(struct pollfd fds[], nfds_t nfds, int timeout)
Wrappers for syscalls, to allow mocking for testing.
Definition: syscall.c:27