cfs-posix.c

00001 /*
00002  * Copyright (c) 2004, Swedish Institute of Computer Science.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the Institute nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  *
00029  * This file is part of the Contiki operating system.
00030  *
00031  * Author: Adam Dunkels <adam@sics.se>
00032  *
00033  * $Id: cfs-posix.c,v 1.15 2009/08/10 09:50:55 nvt-se Exp $
00034  */
00035 
00036 #include <stdio.h>
00037 #include <fcntl.h>
00038 #ifdef _MSC_VER
00039 #include <io.h>
00040 #else
00041 #include <unistd.h>
00042 #endif
00043 
00044 #include "cfs/cfs.h"
00045 
00046 /*---------------------------------------------------------------------------*/
00047 int
00048 cfs_open(const char *n, int f)
00049 {
00050   int s = 0;
00051   if(f == CFS_READ) {
00052     return open(n, O_RDONLY);
00053   } else if(f & CFS_WRITE) {
00054     s = O_CREAT;
00055     if(f & CFS_READ) {
00056       s |= O_RDWR;
00057     } else {
00058       s |= O_WRONLY;
00059     }
00060     if(f & CFS_APPEND) {
00061       s |= O_APPEND;
00062     } else {
00063       s |= O_TRUNC;
00064     }
00065     return open(n, s, 0600);
00066   }
00067   return -1;
00068 }
00069 /*---------------------------------------------------------------------------*/
00070 void
00071 cfs_close(int f)
00072 {
00073   close(f);
00074 }
00075 /*---------------------------------------------------------------------------*/
00076 int
00077 cfs_read(int f, void *b, unsigned int l)
00078 {
00079   return read(f, b, l);
00080 }
00081 /*---------------------------------------------------------------------------*/
00082 int
00083 cfs_write(int f, const void *b, unsigned int l)
00084 {
00085   return write(f, b, l);
00086 }
00087 /*---------------------------------------------------------------------------*/
00088 cfs_offset_t
00089 cfs_seek(int f, cfs_offset_t o, int w)
00090 {
00091   if(w == CFS_SEEK_SET) {
00092     w = SEEK_SET;
00093   } else if(w == CFS_SEEK_CUR) {
00094     w = SEEK_CUR;
00095   } else if(w == CFS_SEEK_END) {
00096     w = SEEK_END;
00097   } else {
00098     return (cfs_offset_t)-1;
00099   }
00100   return lseek(f, o, w);
00101 }
00102 /*---------------------------------------------------------------------------*/
00103 int
00104 cfs_remove(const char *name)
00105 {
00106   return remove(name);
00107 }
00108 /*---------------------------------------------------------------------------*/

Generated on Mon Apr 11 14:23:26 2011 for Contiki 2.5 by  doxygen 1.6.1