/*****************************************************************************\ * Copyright (c) 2004 Mark Aylett * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * * "Software"), to deal in the Software without restriction, including * * without limitation the rights to use, copy, modify, merge, publish, * * distribute, sublicense, and/or sell copies of the Software, and to permit * * persons to whom the Software is furnished to do so, subject to the * * following conditions: * * * * The above copyright notice and this permission notice shall be included * * in all copies or substantial portions of the Software. * * * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN * * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * * USE OR OTHER DEALINGS IN THE SOFTWARE. * \*****************************************************************************/ static const char rcsid[] = "$Id: mar_flags_c.c,v 1.3 2004/12/14 13:09:23 marayl Exp $"; #include "mar_flags_c.h" #include "mar_debug_c.h" #include "mar_types_c.h" #include #include #define MAR_ALL (MAR_RDONLY | MAR_WRONLY | MAR_RDWR \ | MAR_APPEND | MAR_CREAT | MAR_TRUNC | MAR_EXCL) MAR_EXTERN int mar_toflags_(int* to, int from) { #if !defined(WIN32) int flags = 0; #else /* WIN32 */ int flags = O_BINARY; #endif /* WIN32 */ assert(to); if (from & ~MAR_ALL) goto fail; switch (from & (MAR_RDONLY | MAR_WRONLY | MAR_RDWR)) { case MAR_RDONLY: flags |= O_RDONLY; break; case MAR_WRONLY: case MAR_RDWR: flags |= O_RDWR; break; default: goto fail; } if (from & MAR_APPEND) { assert(MAR_APPEND == (from & MAR_APPEND)); flags |= MAR_APPEND; } if (from & MAR_CREAT) { assert(MAR_CREAT == (from & MAR_CREAT)); flags |= O_CREAT; } if (from & MAR_TRUNC) { assert(MAR_TRUNC == (from & MAR_TRUNC)); flags |= O_TRUNC; } if (from & MAR_EXCL) { assert(MAR_EXCL == (from & MAR_EXCL)); flags |= O_EXCL; } *to = flags; return 0; fail: MAR_DEBUG_MSG("Failed to map open flags:" " Invalid source value\n"); errno = EINVAL; return -1; }