dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetC/libc/dirent .cvsignore, NONE, 1.1 Makef


From: Richard Baumann <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetC/libc/dirent .cvsignore, NONE, 1.1 Makefile.am, NONE, 1.1 closedir.c, NONE, 1.1 dirent-glue.cs, NONE, 1.1 opendir.c, NONE, 1.1 readdir.c, NONE, 1.1 readdir_r.c, NONE, 1.1 rewinddir.c, NONE, 1.1 seekdir.c, NONE, 1.1 telldir.c, NONE, 1.1
Date: Fri, 22 Aug 2003 04:15:45 -0400

Update of /cvsroot/dotgnu-pnet/pnetC/libc/dirent
In directory subversions:/tmp/cvs-serv7641/libc/dirent

Added Files:
        .cvsignore Makefile.am closedir.c dirent-glue.cs opendir.c 
        readdir.c readdir_r.c rewinddir.c seekdir.c telldir.c 
Log Message:
Add dirent implementation and example program.


--- NEW FILE ---
Makefile
Makefile.in
.deps

--- NEW FILE ---
AUTOMAKE_OPTIONS = no-dependencies

noinst_LIBRARIES = libCDirent.a

SUFFIXES = .cs

libCDirent_a_SOURCES = closedir.c \
                       dirent-glue.cs \
                       opendir.c \
                       readdir.c \
                       readdir_r.c \
                       rewinddir.c \
                       seekdir.c \
                       telldir.c

AM_CFLAGS = -I$(top_srcdir)/include \
                        -imacros $(top_srcdir)/include/libc-symbols.h \
                        -lOpenSystem.C

.cs.o:
        $(COMPILE) -x cs -o $@ -c $<

--- NEW FILE ---
/*
 * closedir.c - Close a directory stream.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2003  Free Software Foundation, Inc.
 *
 * This library 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <errno.h>
#include <stddef.h>
#include <stdlib.h>
#include <dirent.h>

extern void __syscall_closedir (void *gc_handle, void *err);

int
__closedir (DIR *dirp)
{
  int err;

  if (dirp == NULL || dirp->gc_handle == NULL)
    {
      errno = EBADF;
      return -1;
    }

  err = 0;
  __syscall_closedir (dirp->gc_handle, &err);

  if (err)
    {
      errno = err;
      return -1;
    }

  free (dirp);
  return 0;
}
weak_alias (__closedir, closedir)

--- NEW FILE ---
/*
 * dirent-glue.cs - Glue between dirent and the C# system library.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2003  Free Software Foundation, Inc.
 *
 * This library 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

using System;
using System.Runtime.InteropServices;
using OpenSystem.C;

__module
{
        // Free the underlying managed object for a pnetC directory stream.
        public static void __syscall_closedir(IntPtr gc_handle, IntPtr err)
                        {
                                GCHandle handle = (GCHandle)gc_handle;
                                Directory dir = handle.Target as Directory;
                                if(dir == null)
                                {
                                        Marshal.WriteInt32(err, 9); // EBADF
                                        return;
                                }
                                lock(dir)
                                {
                                        handle.Free();
                                }
                        }

        // Get the underlying managed object for a pnetC directory stream.
        public static IntPtr __syscall_opendir(IntPtr cname, IntPtr err, int 
nameMax)
                        {
                                Directory dir = new Directory(cname, err, 
nameMax);
                                if(Marshal.ReadInt32(err) != 0)
                                {
                                        return IntPtr.Zero;
                                }
                                return (IntPtr)GCHandle.Alloc(dir);
                        }

        // Read an entry from a directory stream.
        // Return value must be freed using Marshal::FreeHGlobal(IntPtr).
        public static IntPtr __syscall_readdir(IntPtr gc_handle, IntPtr err, 
IntPtr len)
                        {
                                GCHandle handle = (GCHandle)gc_handle;
                                Directory dir = handle.Target as Directory;
                                if(dir == null)
                                {
                                        Marshal.WriteInt32(err, 9); // EBADF
                                        return IntPtr.Zero;
                                }
                                lock(dir)
                                {
                                        return dir.Read(err, len);
                                }
                        }

        // Rewind a directory stream's position to the beginning.
        public static void __syscall_rewinddir(IntPtr gc_handle, IntPtr err)
                        {
                                GCHandle handle = (GCHandle)gc_handle;
                                Directory dir = handle.Target as Directory;
                                if(dir == null)
                                {
                                        Marshal.WriteInt32(err, 9); // EBADF
                                        return;
                                }
                                lock(dir)
                                {
                                        dir.Rewind(err);
                                }
                        }

        // Seek to the given position in a directory stream.
        public static void __syscall_seekdir(IntPtr gc_handle, long pos)
                        {
                                GCHandle handle = (GCHandle)gc_handle;
                                Directory dir = handle.Target as Directory;
                                if(dir == null) { return; }
                                lock(dir)
                                {
                                        dir.Pos = pos;
                                }
                        }

        // Get the current position of a directory stream.
        public static long __syscall_telldir(IntPtr gc_handle)
                        {
                                GCHandle handle = (GCHandle)gc_handle;
                                Directory dir = handle.Target as Directory;
                                if(dir == null) { return -1l; }
                                lock(dir)
                                {
                                        return dir.Pos;
                                }
                        }

} // __module

--- NEW FILE ---
/*
 * opendir.c - Open a directory stream, given its name.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2003  Free Software Foundation, Inc.
 *
 * This library 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <errno.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>

extern void *__syscall_opendir (void *name, void *err, int limit);

DIR *
__opendir (const char *name)
{
  DIR *retval;
  int err;
  int limit;

  if (name == NULL || *name == '\0')
    {
      errno = ENOENT;
      return NULL;
    }

  retval = (DIR *)malloc (sizeof(DIR));
  if (retval == NULL)
    {
      errno = ENOMEM;
      return NULL;
    }

  err = 0;
  memset (retval, 0, sizeof(DIR));
  limit = sizeof(retval->current.d_name) - 1;
  retval->gc_handle = __syscall_opendir ((void *)name, &err, limit);

  if (err)
    {
      errno = err;
    }

  return retval;
}
weak_alias (__opendir, opendir)

--- NEW FILE ---
/*
 * readdir.c - Read a directory entry.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2003  Free Software Foundation, Inc.
 *
 * This library 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <errno.h>
#include <stddef.h>
#include <string.h>
#include <dirent.h>

typedef __csharp__(System.Runtime.InteropServices.Marshal) Marshal;

extern void *__syscall_readdir(void *gc_handle, void *err, void *len);

struct dirent *
__readdir (DIR *dirp)
{
  char *str;
  int err;
  int len;

  if (dirp == NULL || dirp->gc_handle == NULL)
    {
      errno = EBADF;
      return NULL;
    }

  err = 0;
  len = 0;
  str = (char *)__syscall_readdir (dirp->gc_handle, &err, &len);

  if (err)
    {
      errno = err;
    }
  if (str == NULL)
    {
      return NULL;
    }
  if (len == 0)
    {
      (void)Marshal::FreeHGlobal((__native__ int)str);
      return NULL;
    }

  strncpy (dirp->current.d_name, str, len);
  dirp->current.d_name[len] = '\0';
  (void)Marshal::FreeHGlobal((__native__ int)str);

  return &(dirp->current);
}
weak_alias (__readdir, readdir)

--- NEW FILE ---
/*
 * readdir_r.c - Read a directory entry into the given entry storage.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2003  Free Software Foundation, Inc.
 *
 * This library 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <errno.h>
#include <stddef.h>
#include <string.h>
#include <dirent.h>

typedef __csharp__(System.Runtime.InteropServices.Marshal) Marshal;

extern void *__syscall_readdir(void *gc_handle, void *err, void *len);

int
__readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result)
{
  char *str;
  int err;
  int len;

  if (dirp == NULL || dirp->gc_handle == NULL)
    {
      errno = EBADF;
      return EBADF;
    }

  err = 0;
  len = 0;
  str = (char *)__syscall_readdir (dirp->gc_handle, &err, &len);

  if (err)
    {
      errno = err;
    }
  if (str == NULL)
    {
      *result = NULL;
      return err;
    }
  if (len == 0)
    {
      (void)Marshal::FreeHGlobal((__native__ int)str);
      *result = NULL;
      return err;
    }

  strncpy (entry->d_name, str, len);
  entry->d_name[len] = '\0';
  (void)Marshal::FreeHGlobal((__native__ int)str);
  *result = entry;

  return err;
}
weak_alias (__readdir_r, readdir_r)

--- NEW FILE ---
/*
 * rewinddir.c - Rewind the DIR position to the beginning of the directory.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2003  Free Software Foundation, Inc.
 *
 * This library 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <stddef.h>
#include <dirent.h>

extern void __syscall_rewinddir(void *gc_handle, void *err);

void
__rewinddir (DIR *dirp)
{
  int err;

  if (dirp == NULL || dirp->gc_handle == NULL)
    {
      return;
    }

  err = 0;
  __syscall_rewinddir (dirp->gc_handle, &err);
}
weak_alias (__rewinddir, rewinddir)

--- NEW FILE ---
/*
 * seekdir.c - Seek to the given position in a DIR.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2003  Free Software Foundation, Inc.
 *
 * This library 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <stddef.h>
#include <dirent.h>

extern void __syscall_seekdir(void *gc_handle, long long pos);

void
__seekdir (DIR *dirp, long pos)
{
  if (dirp == NULL || dirp->gc_handle == NULL)
    {
      return;
    }

  __syscall_seekdir (dirp->gc_handle, (long long)pos);
}
weak_alias (__seekdir, seekdir)

--- NEW FILE ---
/*
 * telldir.c - Get the current position of a DIR.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2003  Free Software Foundation, Inc.
 *
 * This library 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <stddef.h>
#include <dirent.h>

extern long long __syscall_telldir(void *gc_handle);

long
__telldir (DIR *dirp)
{
  if (dirp == NULL || dirp->gc_handle == NULL)
    {
      return -1l;
    }

  return (long)__syscall_telldir (dirp->gc_handle);
}
weak_alias (__telldir, telldir)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]