1/*
2 * Copyright (c) 2007, 2008, 2009, 2011, 2013, ETH Zurich.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, CAB F.78, Universitaetstr. 6, CH-8092 Zurich,
8 * Attn: Systems Group.
9 */
10
11#include <unistd.h>
12#include <stdio.h>
13#include <lwip/sys.h>
14#include <lwip/sockets.h>
15#include <vfs/vfs_fd.h>
16#include <vfs/fdtab.h>
17#include "posixcompat.h"
18#include "pty.h"
19
20__weak_reference(write, _write);
21ssize_t write(int fd, const void *buf, size_t len)
22{
23    int ret;
24    struct fdtab_entry *e = fdtab_get(fd);
25
26    switch(e->type) {
27    case FDTAB_TYPE_LWIP_SOCKET:
28        lwip_mutex_lock();
29        ret = lwip_write(e->fd, buf, len);
30        lwip_mutex_unlock();
31        break;
32
33    case FDTAB_TYPE_UNIX_SOCKET:
34        ret = send(fd, buf, len, 0);
35        break;
36
37    case FDTAB_TYPE_PTM:
38        ret = ptm_write(fd, buf, len);
39        break;
40
41    case FDTAB_TYPE_PTS:
42        ret = pts_write(fd, buf, len);
43        break;
44
45    default:
46        ret = vfsfd_write(fd, buf, len);
47        break;
48    }
49
50    return ret;
51}
52