bjh         99/04/09 11:39:16

  Added:       apr/file_io/os2 filedup.c filestat.c maperrorcode.c open.c
                        readwrite.c seek.c
  Log:
  Implementation of basic file I/O for OS/2.
  
  Revision  Changes    Path
  1.1                  apache-apr/apr/file_io/os2/filedup.c
  
  Index: filedup.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  
  #include "apr_file_io.h"
  #include "apr_general.h"
  #include <string.h>
  
  #define INCL_DOS
  #include <os2.h>
  
  apr_file_t *apr_dupfile(apr_file_t *old_file)
  {
      int rv;
      apr_file_t * new_file = (apr_file_t *)malloc(sizeof(apr_file_t));
      
      if (new_file == NULL) {
          errno = ENOMEM;
          return NULL;
      } 
      
      rv = DosDupHandle(old_file->filedes, (ULONG *)&new_file->filedes);
      
      if ( rv ) {
          errno = os2errno(rv);
          free(new_file);
          return NULL;
      }
      
      old_file->filedes = new_file->filedes; 
      old_file->fname = strdup(new_file->fname);
      old_file->buffered = new_file->buffered;
      old_file->protection = new_file->protection;
      old_file->user = new_file->user;
      old_file->group = new_file->group;
      old_file->size = new_file->size;
      old_file->atime = new_file->atime;    
      old_file->mtime = new_file->mtime;
      old_file->ctime = new_file->ctime;
  }
  
  
  
  1.1                  apache-apr/apr/file_io/os2/filestat.c
  
  Index: filestat.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  
  #include "apr_file_io.h"
  #include "apr_general.h"
  #include "apr_errno.h"
  
  #define INCL_DOS
  #include <os2.h>
  
  
  typedef struct {
    USHORT sec2:5;
    USHORT min:6;
    USHORT hour:5;
  } DOSTIME;
  
  typedef struct {
    USHORT day:5;
    USHORT month:4;
    USHORT year:7;
  } DOSDATE;
  
  long os2date2unix( FDATE os2date, FTIME os2time )
  {
    struct tm tmpdate;
  
    memset(&tmpdate, 0, sizeof(tmpdate));
    tmpdate.tm_hour  = os2time.hours;
    tmpdate.tm_min   = os2time.minutes;
    tmpdate.tm_sec   = os2time.twosecs * 2;
  
    tmpdate.tm_mday  = os2date.day;
    tmpdate.tm_mon   = os2date.month - 1;
    tmpdate.tm_year  = os2date.year + 80;
    tmpdate.tm_isdst = -1;
  
    return mktime( &tmpdate );
  }
  
  apr_status_t apr_getfileinfo(char * fname, apr_file_t *thefile)
  {
      FILESTATUS3 info;
      int rv = DosQueryPathInfo(fname, FIL_STANDARD, &info, sizeof(info));
  
      if (rv == 0) {
          thefile->protection = (info.attrFile & FILE_READONLY) ? 0555 : 0777;
          thefile->user = 0;
          thefile->group = 0;
          thefile->size = info.cbFile;
          thefile->atime = os2date2unix(info.fdateLastAccess, 
info.ftimeLastAccess);
          thefile->mtime = os2date2unix(info.fdateLastWrite, 
info.ftimeLastWrite);
          thefile->ctime = os2date2unix(info.fdateCreation, info.ftimeCreation);
          return APR_SUCCESS;
      }
      else {
          errno = ENOSTAT;
          return APR_FAILURE;
      }
  }
  
  apr_status_t apr_updatefileinfo(apr_file_t *thefile)
  {
      FILESTATUS3 info;
      int rv = DosQueryFileInfo(thefile->filedes, FIL_STANDARD, &info, 
sizeof(info));
  
      if (rv == 0) {
          thefile->protection = (info.attrFile & FILE_READONLY) ? 0555 : 0777;
          thefile->user = 0;
          thefile->group = 0;
          thefile->size = info.cbFile;
          thefile->atime = os2date2unix(info.fdateLastAccess, 
info.ftimeLastAccess);
          thefile->mtime = os2date2unix(info.fdateLastWrite, 
info.ftimeLastWrite);
          thefile->ctime = os2date2unix(info.fdateCreation, info.ftimeCreation);
          return APR_SUCCESS;
      }
      else {
          errno = ENOSTAT;
          return APR_FAILURE;
      }
  }
  
  
  
  
  
  
  1.1                  apache-apr/apr/file_io/os2/maperrorcode.c
  
  Index: maperrorcode.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  
  #include "apr_file_io.h"
  #include <errno.h>
  #include <string.h>
  
  #define INCL_DOSERRORS
  #include <os2.h>
  
  int errormap[][2] = {
      { ERROR_FILE_NOT_FOUND,       ENOENT       },
      { ERROR_PATH_NOT_FOUND,       ENOENT       },
      { ERROR_TOO_MANY_OPEN_FILES,  EMFILE       },
      { ERROR_ACCESS_DENIED,        EACCES       },
      { ERROR_SHARING_VIOLATION,    EACCES       },
      { ERROR_INVALID_PARAMETER,    EINVAL       },
      { ERROR_OPEN_FAILED,          ENOENT       },
      { ERROR_DISK_FULL,            ENOSPC       },
      { ERROR_FILENAME_EXCED_RANGE, ENAMETOOLONG },
      { ERROR_INVALID_FUNCTION,     EINVAL       },
      { ERROR_INVALID_HANDLE,       EBADF        },
      { ERROR_NEGATIVE_SEEK,        ESPIPE       }
  };
  
  #define MAPSIZE (sizeof(errormap)/sizeof(errormap[0]))
  
  int os2errno( ULONG oserror )
  {
      int rv = -1, index;
      
      for (index=0; index<MAPSIZE && errormap[index][0] != oserror; index++);
      
      if (index<MAPSIZE)
          rv = errormap[index][1];
          
      return rv;
  }
  
  
  
  1.1                  apache-apr/apr/file_io/os2/open.c
  
  Index: open.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  
  #include "apr_file_io.h"
  #include <errno.h>
  #include <string.h>
  
  #define INCL_DOS
  #include <os2.h>
  
  apr_file_t *apr_open(char *fname, apr_int32_t flag,  apr_fileperms_t mode)
  {
      int oflags = 0;
      int mflags = OPEN_FLAGS_FAIL_ON_ERROR|OPEN_SHARE_DENYNONE;
      int rv;
      apr_file_t *dafile = (apr_file_t *)malloc(sizeof(apr_file_t));
      struct stat info;
      ULONG action;
  
      if ((flag & APR_READ) && (flag & APR_WRITE)) {
          mflags |= OPEN_ACCESS_READWRITE;
      } else if (flag & APR_READ) {
          mflags |= OPEN_ACCESS_READONLY;
      } else if (flag & APR_WRITE) {
          mflags |= OPEN_ACCESS_WRITEONLY;
      } else {
          errno = EACCES;
          free(dafile);
          return NULL;
      }
  
      if (flag & APR_BUFFERED) {
          dafile->buffered = TRUE;
      }
  
      if (flag & APR_CREATE) {
          oflags |= OPEN_ACTION_CREATE_IF_NEW; 
          if (!(flag & APR_EXCL)) {
              if (flag & APR_APPEND)
                  oflags |= OPEN_ACTION_OPEN_IF_EXISTS;
              else
                  oflags |= OPEN_ACTION_REPLACE_IF_EXISTS;
          }
      }
      
      if ((flag & APR_EXCL) && !(flag & APR_CREATE)) {
          errno = EACCES;
          free(dafile);
          return NULL;
      }
  
      if (flag & APR_TRUNCATE) {
          oflags |= OPEN_ACTION_REPLACE_IF_EXISTS;
      }
      
      rv = DosOpen(fname, (HFILE *)&(dafile->filedes), &action, 0, 0, oflags, 
mflags, NULL);
      
      if (rv == 0 && (flag & APR_APPEND)) {
          ULONG newptr;
          rv = DosSetFilePtr(dafile->filedes, 0, FILE_END, &newptr );
      }
      
      if (rv != 0) {
          free(dafile);
          return NULL;
      }
  
      if (apr_updatefileinfo(dafile) == APR_SUCCESS) {
          dafile->fname = strdup(fname);
          return dafile;
      } else {
          errno = ENOSTAT;
          free(dafile);
          return NULL;
      }
  }
  
  apr_status_t apr_close(apr_file_t *file)
  {
      if (DosClose(file->filedes) == 0) {
          free(file->fname);
          free(file);
          return APR_SUCCESS;
      } else {
          return APR_FAILURE;
          /* Are there any error conditions other than EINTR or EBADF? */
      }
  }
  
  apr_status_t apr_remove_file(char *path)
  {
      if (DosDelete(path) == 0) {
          return APR_SUCCESS;
      }
      else {
          return APR_FAILURE;
      }
  }
  
  
  
  
  1.1                  apache-apr/apr/file_io/os2/readwrite.c
  
  Index: readwrite.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  
  #include "apr_file_io.h"
  #include "apr_general.h"
  #include "apr_errno.h"
  #include <errno.h>
  #include <unistd.h>
  
  apr_ssize_t apr_read(apr_file_t *thefile, void *buf, apr_ssize_t nbytes)
  {
      apr_size_t rv;
  
      if (thefile->filedes < 0) {
          errno = EBADF;
          return -1;
      }
  
      rv = read(thefile->filedes, buf, nbytes);
  
      return rv;
  }
  
  apr_ssize_t apr_write(apr_file_t *thefile, void * buf, apr_ssize_t nbytes)
  {
      apr_size_t rv;
      struct stat info;
  
      if (thefile->filedes < 0) {
          errno = EBADF;
          return -1;
      }
  
      rv = write(thefile->filedes, buf, nbytes);
  
      if (stat(thefile->fname, &info) == 0) {
          thefile->size = info.st_size;
          thefile->atime = info.st_atime;
          thefile->mtime = info.st_mtime;
          thefile->ctime = info.st_ctime;
      }
      return rv;
  }
  
  
  
  1.1                  apache-apr/apr/file_io/os2/seek.c
  
  Index: seek.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  
  #include "apr_file_io.h"
  #include <errno.h>
  #include <string.h>
  #include <io.h>
  
  #define INCL_DOS
  #include <os2.h>
  
  int os2errno( ULONG oserror );
  
  apr_off_t apr_seek(apr_file_t *file, apr_off_t offset, apr_seek_where_t 
origin)
  {
      int rv;
      ULONG newpos;
      
      switch (origin) {
          case APR_SET:
              origin = FILE_BEGIN;
              break;
              
          case APR_CUR:
              origin = FILE_CURRENT;
              break;
              
          case APR_END:
              origin = FILE_END;
              break;
      }
              
      rv = DosSetFilePtr(file->filedes, offset, origin, &newpos);
      printf( "DosSetFilePtr()=%d\n", rv );
      
      if (rv) {
          errno = os2errno( rv );
          return -1;
      }
      
      return newpos;
  }
  
  
  

Reply via email to