/****************************************************************************** * Copyright (c) 2004, 2008 IBM Corporation * All rights reserved. * This program and the accompanying materials * are made available under the terms of the BSD License * which accompanies this distribution, and is available at * http://www.opensource.org/licenses/bsd-license.php * * Contributors: * IBM Corporation - initial implementation *****************************************************************************/ #include #include #include #include #include #include #include extern int vsprintf(char *, const char *, va_list); extern void _exit(int status); void exit(int status); int open(const char* name, int flags) { int fd; /* search free file descriptor */ for (fd=0; fd= FILEIO_MAX || fd_array[fd].type == FILEIO_TYPE_EMPTY) return -1; if (fd_array[fd].type == FILEIO_TYPE_FILE) of_close(fd_array[fd].ih); fd_array[fd].type = FILEIO_TYPE_EMPTY; return 0; } ssize_t read(int fd, void *buf, size_t len) { if (fd < 0 || fd >= FILEIO_MAX || fd_array[fd].type == FILEIO_TYPE_EMPTY) return -1; return of_read(fd_array[fd].ih, buf, len); } ssize_t write (int fd, const void *buf, size_t len) { char dest_buf[512]; char *dest_buf_ptr; const char *dbuf = buf; int i; if (fd == 1 || fd == 2) { dest_buf_ptr = &dest_buf[0]; for (i = 0; i < len && i < 256; i++) { *dest_buf_ptr++ = *dbuf++; if (dbuf[-1] == '\n') *dest_buf_ptr++ = '\r'; } len = dest_buf_ptr - &dest_buf[0]; buf = &dest_buf[0]; } if(fd < 0 || fd >= FILEIO_MAX || fd_array[fd].type == FILEIO_TYPE_EMPTY) return -1; return of_write(fd_array[fd].ih, (void *)buf, len); } ssize_t lseek (int fd, long offset, int whence) { return 0; // this syscall is unused !!! #if 0 if (whence != 0) return -1; of_seek (fd_array[fd], (unsigned int) (offset>>32), (unsigned int) (offset & 0xffffffffULL)); return offset; #endif } int recv(int fd, void *packet, int packet_len, int flags) { return read(fd, packet, packet_len); } int send(int fd, const void *packet, int packet_len, int flags) { return write(fd, packet, packet_len); } int sendto(int fd, const void *packet, int packet_len, int flags, const void *sock_addr, int sock_addr_len) { return send(fd, packet, packet_len, flags); } void exit(int status) { _exit(status); }