Client implementation of the 9P protocol for constrained devices
git clone https://git.8pit.net/ninenano.git
1/** 2 * Retrieve value of environment variable using getenv(3) and return 3 * `EXIT_FAILURE` if the result was a NULL pointer. 4 * 5 * @param VAR Name of the variable to store result in. 6 * @param ENV Name of the environment variable. 7 */ 8#define GETENV(VAR, ENV) \ 9 do { if (!(VAR = getenv(ENV))) { \10 fprintf(stderr, "%s is not set or empty\n", ENV); \11 return EXIT_FAILURE; } \12 } while (0)1314/**15 * Global socket for 9P protocol connection.16 */17static sock_tcp_t psock;1819/**20 * Function used to receive data from a TCP sock connection. This21 * function is intended to be used as an ::iofunc for ::_9pinit.22 */23static ssize_t24recvfn(void *buf, size_t count)25{26 return sock_tcp_read(&psock, buf, count, SOCK_NO_TIMEOUT);27}2829/**30 * Function used to send data to a TCP server. This function is intended31 * to be used as an ::iofunc for ::_9pinit.32 */33static ssize_t34sendfn(void *buf, size_t count)35{36 return sock_tcp_write(&psock, buf, count);37}3839/**40 * Returns the amount of currently opened fids.41 *42 * @param fids Pointer to the fid table.43 * @return Amount of open fids in the fid table.44 */45static size_t46cntfids(_9pfid *fids)47{48 size_t i, n;4950 for (i = n = 0; i < _9P_MAXFIDS; i++)51 if (fids[i].fid) n++;5253 return n;54}