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/time .cvsignore,NONE,1.1 Makefile


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetC/libc/time .cvsignore,NONE,1.1 Makefile.am,NONE,1.1 clock.c,NONE,1.1 gmtime.c,NONE,1.1 time-defs.h,NONE,1.1 time-glue.cs,NONE,1.1 time-vars.c,NONE,1.1 time.c,NONE,1.1tzset.c,NONE,1.1
Date: Sun, 16 Feb 2003 22:24:46 -0500

Update of /cvsroot/dotgnu-pnet/pnetC/libc/time
In directory subversions:/tmp/cvs-serv2164/libc/time

Added Files:
        .cvsignore Makefile.am clock.c gmtime.c time-defs.h 
        time-glue.cs time-vars.c time.c tzset.c 
Log Message:


Implement some of the ANSI C time routines.


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

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

noinst_LIBRARIES = libCTime.a

SUFFIXES = .cs

libCTime_a_SOURCES = clock.c \
                     gmtime.c \
                     time.c \
                     time-defs.h \
                                         time-glue.cs \
                                         time-vars.c \
                                         tzset.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 ---
/*
 * clock.c - Get the amount of time since the process was started.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * 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 <time.h>
#include "time-defs.h"

clock_t
clock (void)
{
  if (!__startup_time)
    __startup_time = __syscall_utc_time ();
  return (clock_t)((__syscall_utc_time () - __startup_time)
                       / TICKS_PER_CLOCKS);
}

--- NEW FILE ---
/*
 * gmtime.c - Convert a time_t value into GMT or local time.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * 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 <time.h>
#include "time-defs.h"

static struct tm gmbuf;
static struct tm locbuf;

struct tm *
gmtime (time_t *timer)
{
  __syscall_unpack_time (TIME_TO_TICKS (*timer), (__native__ int)&gmbuf,
                         (_Bool)0);
  return &gmbuf;
}

struct tm *
gmtime_r (time_t * __restrict timer, struct tm * __restrict tp)
{
  __syscall_unpack_time (TIME_TO_TICKS (*timer), (__native__ int)tp,
                         (_Bool)0);
  return tp;
}

struct tm *
localtime (time_t *timer)
{
  if (!__tz_is_set)
    tzset ();
  __syscall_unpack_time (TIME_TO_TICKS (*timer), (__native__ int)&locbuf,
                         (_Bool)1);
  return &locbuf;
}

struct tm *
localtime_r (time_t * __restrict timer, struct tm * __restrict tp)
{
  if (!__tz_is_set)
    tzset ();
  __syscall_unpack_time (TIME_TO_TICKS (*timer), (__native__ int)tp,
                         (_Bool)1);
  return tp;
}

--- NEW FILE ---
/*
 * time-defs.h - Useful definitions for handling C# <-> C time conversions.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * 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
 */

#ifndef _TIME_DEFS_H
#define _TIME_DEFS_H

extern long long __syscall_utc_time (void);
extern long long __syscall_local_time (void);
extern void __syscall_unpack_time (long long ticks, __native__ int tm,
                                   _Bool is_local);

#define EPOCH_ADJUST        62135596800LL
#define TICKS_PER_SEC       10000000LL
#define TICKS_PER_CLOCKS    10LL

#define TIME_TO_TICKS(t)        (((t) + EPOCH_ADJUST) * TICKS_PER_SEC)

extern int __tz_is_set;
extern long long __startup_time;

#endif /* _TIME_DEFS_H */

--- NEW FILE ---
/*
 * time-glue.cs - Glue between time and the C# system library.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * 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;

__module
{

        // Get the current system time in UTC.
        public static long __syscall_utc_time()
                        {
                                return DateTime.UtcNow.Ticks;
                        }

        // Get the current system time in local time.
        public static long __syscall_local_time()
                        {
                                return DateTime.Now.Ticks;
                        }

        // Unpack a tick value into a "struct tm" structure.
        public static void __syscall_unpack_time
                                (long ticks, IntPtr tm, bool is_local)
                        {
                                DateTime dt;
                                if(is_local)
                                {
                                        long tz = __syscall_utc_time() - 
__syscall_local_time();
                                        dt = new DateTime(ticks + tz);
                                }
                                else
                                {
                                        dt = new DateTime(ticks);
                                }
                                Marshal.WriteInt32(tm, 0, dt.Second);
                                Marshal.WriteInt32(tm, 4, dt.Minute);
                                Marshal.WriteInt32(tm, 8, dt.Hour);
                                Marshal.WriteInt32(tm, 12, dt.Day);
                                Marshal.WriteInt32(tm, 16, dt.Month - 1);
                                Marshal.WriteInt32(tm, 20, dt.Year - 1900);
                                Marshal.WriteInt32(tm, 24, (int)(dt.DayOfWeek));
                                Marshal.WriteInt32(tm, 28, dt.DayOfYear);
                                Marshal.WriteInt32(tm, 32, 0);  /* TODO - 
tm_isdst */
                        }

} // __module

--- NEW FILE ---
/*
 * time-vars.c - Global variables for the time routines.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * 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 <time.h>
#include "time-defs.h"

int __tz_is_set = 0;
int daylight = 0;
long timezone = 0;
char *tzname[2] = {"GMT", 0};
long long __startup_time;

static void
init_time (void) __attribute__ ((__constructor__))
{
  tzset ();
  __startup_time = __syscall_utc_time ();
}

--- NEW FILE ---
/*
 * time.c - Get the current system time.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * 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 <time.h>
#include "time-defs.h"

time_t
time (time_t *timer)
{
  long long t = __syscall_utc_time ();
  time_t t2 = (time_t)((t / TICKS_PER_SEC) - EPOCH_ADJUST);
  if ( timer )
    *timer = t2;
  return t2;
}

--- NEW FILE ---
/*
 * tzset.c - Set the global timezone information.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * 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 <time.h>
#include "time-defs.h"

void
tzset (void)
{
  /* TODO - "daylight" and "tzname" */
  timezone = (long)((__syscall_utc_time () - __syscall_local_time ())
                           / TICKS_PER_SEC);
  if ( timezone != 0 )
    tzname[0] = "???";
  __tz_is_set = 1;
}





reply via email to

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