rbb         99/02/26 09:06:45

  Added:       apr/file_io/beos Makefile filedup.c filestat.c open.c
                        readwrite.c
  Log:
  Initial revision of apr file_io logic for BeOS.
  Submitted by: David Reid
  
  Revision  Changes    Path
  1.1                  apache-apr/apr/file_io/beos/Makefile
  
  Index: Makefile
  ===================================================================
  ##
  ##  Apache Makefile, automatically generated by Configure script.
  ##  Hand-edited changes will be lost if the Configure script is re-run.
  ##  Sources: - ../Makefile.config (via Configuration.apaci)
  ##           - ./Makefile.tmpl
  ##
  
  ##
  ##  Inherited Makefile options from Configure script
  ##  (Begin of automatically generated section)
  ##
  SRCDIR=..
  EXTRA_CFLAGS=-g 
  EXTRA_LDFLAGS=
  EXTRA_LIBS=
  EXTRA_INCLUDES=
  EXTRA_DEPS=
  OSDIR=
  INCDIR=../../../include
  INCLUDES0=-I $(INCDIR)
  SHELL=/bin/sh
  CC=gcc
  CPP=gcc -E
  TARGET=
  OPTIM=
  CFLAGS_SHLIB=-fpic -DSHARED_MODULE
  LD_SHLIB=ld
  LDFLAGS_SHLIB=-Bshareable
  LDFLAGS_SHLIB_EXPORT=-rdynamic
  CFLAGS1= -DBEOS -DUSE_HSREGEX
  INCLUDES1=
  LIBS_SHLIB=
  LDFLAGS1=
  MFLAGS_STATIC=--no-print-directory
  REGLIB=regex/libregex.a
  RANLIB=ranlib
  LIBS1= #-lm -lcrypt -lndbm -ldl
  ##
  ##  (End of automatically generated section)
  ##
  
  
  CFLAGS=$(OPTIM) $(CFLAGS1) $(EXTRA_CFLAGS)
  LIBS=$(EXTRA_LIBS) $(LIBS1)
  INCLUDES=$(INCLUDES1) $(INCLUDES0) $(EXTRA_INCLUDES)
  LDFLAGS=$(LDFLAGS1) $(EXTRA_LDFLAGS)
  
  LIB=  libfile.a
  
  OBJS= open.o readwrite.o filedup.o filestat.o\
  
  .c.o:
        $(CC) -c $(INCLUDES) $(CFLAGS) $<
  
  all: $(HEADERS) $(LIB)
  
  $(LIB): $(OBJS)
        rm -f $@
        ar cr $@ $(OBJS)
        $(RANLIB) $@
        cp $@ ../
  clean:
        rm -f *.o $(LIB)
  
  distclean: clean
        -rm -f Makefile
  
  # We really don't expect end users to use this rule.  It works only with
  # gcc, and rebuilds Makefile.tmpl.  You have to re-run Configure after
  # using it.
  depend:
        cp Makefile.tmpl Makefile.tmpl.bak \
            && sed -ne '1,/^# DO NOT REMOVE/p' Makefile.tmpl > Makefile.new \
            && gcc -MM $(INCLUDES) $(CFLAGS) *.c >> Makefile.new \
            && sed -e '1,$$s: $(INCDIR)/: $$(INCDIR)/:g' \
                   -e '1,$$s: $(OSDIR)/: $$(OSDIR)/:g' Makefile.new \
                > Makefile.tmpl \
            && rm Makefile.new
  
  #Dependencies
  
  $(OBJS): Makefile
  
  # DO NOT REMOVE
  open.o: open.c filestat.c
  readwrite.o: readwrite.c
  filedup.o: filedup.c
  filestat.o: filestat.c
  
  
  
  1.1                  apache-apr/apr/file_io/beos/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"
  
  apr_file_t *apr_dupfile(apr_file_t *old_file)
  {
      apr_file_t * new_file = (apr_file_t *)malloc(sizeof(apr_file_t));
      
      if (new_file == NULL) {
          errno = ENOMEM;
          return NULL;
      } 
      old_file->filedes = new_file->filedes; 
      old_file->fname = 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/beos/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"
  
  apr_status_t apr_getfileinfo(char * fname, apr_file_t *thefile)
  {
      struct stat info;
      int rv = stat(fname, &info);
  
      if (rv == 0) {
          thefile->protection = info.st_mode;
          thefile->user = info.st_uid;
          thefile->group = info.st_gid;
          thefile->size = info.st_size;
          thefile->atime = info.st_atime;
          thefile->mtime = info.st_mtime;
          thefile->ctime = info.st_ctime;
          return APR_SUCCESS;
      }
      else {
          errno = ENOSTAT;
          return APR_FAILURE;
      }
  }
  
  apr_status_t apr_updatefileinfo(apr_file_t *thefile)
  {
      struct stat info;
      int rv = fstat(thefile->filedes, &info);
  
      if (rv == 0) {
          thefile->protection = info.st_mode;
          thefile->user = info.st_uid;
          thefile->group = info.st_gid;
          thefile->size = info.st_size;
          thefile->atime = info.st_atime;
          thefile->mtime = info.st_mtime;
          thefile->ctime = info.st_ctime;
          return APR_SUCCESS;
      }
      else {
          errno = ENOSTAT;
          return APR_FAILURE;
      }
  }
  
  
  
  
  
  
  1.1                  apache-apr/apr/file_io/beos/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/>.
   *
   */
  
  
  // BeOS port by David Reid 23 Feb 1999
  
  #include "apr_file_io.h"
  #include <errno.h>
  #include <support/SupportDefs.h>
  #include <kernel/OS.h>
  #include <stdlib.h>
  #include <unistd.h>
  #include <stdio.h>
  
  apr_file_t *apr_open(char *fname, apr_int32_t flag,  apr_fileperms_t mode)
  {
      int oflags = 0;
      apr_file_t *dafile = (apr_file_t *)malloc(sizeof(apr_file_t));
      struct stat info;
  
      if ((flag & APR_READ) && (flag & APR_WRITE)) {
          oflags = B_READ_WRITE;
      }
      else if (flag & APR_READ) {
          oflags = B_READ_ONLY;
      }
      else if (flag & APR_WRITE) {
          oflags = B_WRITE_ONLY;
      }
      else {
          errno = EACCES;
                free (dafile);
                return NULL;
      }
      //strcpy(dafile->fname, fname);
        dafile->fname = fname;
      if (flag & APR_CREATE) {
          oflags |= B_CREATE_FILE; 
                if (flag & APR_EXCL) {
                    oflags |= B_FAIL_IF_EXISTS;
                }
      }
      if ((flag & APR_EXCL) && !(flag & APR_CREATE)) {
          errno = EACCES;
                free (dafile);
                return NULL;
      }   
  
      if (flag & APR_APPEND) {
          oflags |= B_OPEN_AT_END;
      }
      if (flag & APR_TRUNCATE) {
          oflags |= B_ERASE_FILE;
      }
      dafile->filedes = open(fname, oflags, mode);
      
      if (dafile->filedes < 0) {
          dafile->filedes = -1;
                free (dafile);
          return NULL;
      }
  
      if (apr_updatefileinfo(dafile) == APR_SUCCESS) {
                return dafile;
      }
      else {
          errno = ENOSTAT;
                free (dafile);
                return NULL;
      }
  }
  
  apr_status_t apr_close(apr_file_t * file)
  {
      if (close(file->filedes) == 0) {
          file->filedes = -1;
          return APR_SUCCESS;
      }
      else {
          return APR_FAILURE;
        /* Are there any error conditions other than EINTR or EBADF? */
      }
  }
  
  
  
  1.1                  apache-apr/apr/file_io/beos/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_uint64_t apr_read(apr_file_t *thefile, void *buf, apr_uint64_t nbytes)
  {
      apr_int64_t rv;
  
      if (thefile->filedes < 0) {
          errno = EBADF;
          return -1;
      }
  
      rv = read(thefile->filedes, buf, nbytes);
  
      return rv;
  }
  
  apr_uint64_t apr_write(apr_file_t *thefile, void * buf, apr_uint64_t nbytes)
  {
      apr_int64_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;
  }
  
  
  

Reply via email to