/* * Copyright (c) 2002-2011 by XMLVM.org * * Project Info: http://www.xmlvm.org * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. */ #include #include #include #include #include #include #include "xmlvm-hy.h" #include "xmlvm-file.h" #include "hycomp.h" /** * This will convert all separators to the proper platform separator * and remove duplicates on non POSIX platforms. */ void ioh_convertToPlatform (char *path) { char *pathIndex; #if !(DIR_SEPARATOR == '/') size_t length = strlen (path); #endif /* Convert all separators to the same type */ pathIndex = path; while (*pathIndex != '\0') { if ((*pathIndex == '\\' || *pathIndex == '/') && (*pathIndex != DIR_SEPARATOR)) *pathIndex = DIR_SEPARATOR; pathIndex++; } #if !(DIR_SEPARATOR == '/') /* Remove duplicate initial separators */ pathIndex = path; while ((*pathIndex != '\0') && (*pathIndex == DIR_SEPARATOR)) { pathIndex++; } if ((pathIndex > path) && ((int)length > (pathIndex - path)) && (*(pathIndex + 1) == ':')) { /* For Example '////c:/!*' (! added to avoid gcc warning) */ size_t newlen = length - (pathIndex - path); memmove (path, pathIndex, newlen); path[newlen] = '\0'; } else { if ((pathIndex - path > 3) && ((int)length > (pathIndex - path))) { /* For Example '////serverName/!*' (! added to avoid gcc warning) */ size_t newlen = length - (pathIndex - path) + 2; memmove (path, pathIndex - 2, newlen); path[newlen] = '\0'; } } /* This will have to handle extra \'s but currently doesn't */ #endif } static I_32 EsTranslateOpenFlags (I_32 flags) { I_32 realFlags = 0; if (flags & HyOpenAppend) { realFlags |= O_APPEND; } if (flags & HyOpenTruncate) { realFlags |= O_TRUNC; } if (flags & HyOpenCreate) { realFlags |= O_CREAT; } if (flags & HyOpenCreateNew) { realFlags |= O_EXCL | O_CREAT; } #ifdef O_SYNC if (flags & HyOpenSync) { realFlags |= O_SYNC; } #endif if (flags & HyOpenRead) { if (flags & HyOpenWrite) { return (O_RDWR | realFlags); } return (O_RDONLY | realFlags); } if (flags & HyOpenWrite) { return (O_WRONLY | realFlags); } return -1; } static I_32 findError (I_32 errorCode) { switch (errorCode) { case EACCES: case EPERM: return HYPORT_ERROR_FILE_NOPERMISSION; case ENAMETOOLONG: return HYPORT_ERROR_FILE_NAMETOOLONG; case ENOENT: return HYPORT_ERROR_FILE_NOENT; case ENOTDIR: return HYPORT_ERROR_FILE_NOTDIR; case ELOOP: return HYPORT_ERROR_FILE_LOOP; case EBADF: return HYPORT_ERROR_FILE_BADF; case EEXIST: return HYPORT_ERROR_FILE_EXIST; case ENOSPC: case EFBIG: return HYPORT_ERROR_FILE_DISKFULL; default: return HYPORT_ERROR_FILE_OPFAILED; } } I_32 hyfile_close (IDATA fd) { #if (FD_BIAS != 0) if (fd < FD_BIAS) { /* Cannot close STD streams, and no other FD's should exist HySeekEnd)) { return -1; } /* If file offsets are 32 bit, truncate the seek to that range */ if (sizeof (off_t) < sizeof (I_64)) { if (offset > 0x7FFFFFFF) { localOffset = 0x7FFFFFFF; } else if (offset < -0x7FFFFFFF) { localOffset = -0x7FFFFFFF; } } #if (FD_BIAS != 0) if (fd < FD_BIAS) { /* Cannot seek on STD streams, and no other FD's should exist