home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ixemul-45.0-src.tgz / tar.out / contrib / ixemul / library / utimes.c < prev    next >
C/C++ Source or Header  |  1996-10-01  |  3KB  |  91 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  utimes.c,v 1.1.1.1 1994/04/04 04:30:38 amiga Exp
  20.  *
  21.  *  utimes.c,v
  22.  * Revision 1.1.1.1  1994/04/04  04:30:38  amiga
  23.  * Initial CVS check in.
  24.  *
  25.  *  Revision 1.1  1992/05/14  19:55:40  mwild
  26.  *  Initial revision
  27.  *
  28.  */
  29.  
  30. #define _KERNEL
  31. #include "ixemul.h"
  32. #include "kprintf.h"
  33.  
  34. static int
  35. __utimes_func (struct StandardPacket *sp, struct MsgPort *handler,
  36.                BPTR parent_lock,
  37.            BSTR name,
  38.            struct DateStamp *ds, int *no_error)
  39. {
  40.   sp->sp_Pkt.dp_Type = ACTION_SET_DATE;
  41.   sp->sp_Pkt.dp_Arg1 = 0;
  42.   sp->sp_Pkt.dp_Arg2 = parent_lock;
  43.   sp->sp_Pkt.dp_Arg3 = name;
  44.   sp->sp_Pkt.dp_Arg4 = (long)  ds;
  45.   
  46.   PutPacket (handler, sp);
  47.   __wait_sync_packet (sp);
  48.   *no_error = sp->sp_Pkt.dp_Res1 == -1;
  49.  
  50.   /* we want to set the date of the file pointed to, not that of the link */
  51.   return 1;
  52. }
  53.  
  54.  
  55. int
  56. utimes(char *name, struct timeval *tvp)
  57. {
  58.   struct DateStamp *ds;
  59.   struct timeval tv;
  60.   int result;
  61.   
  62.   if (!tvp)
  63.     /* in this case, fill in the current time */
  64.     syscall (SYS_gettimeofday, & tv, 0);
  65.   else
  66.     /* we have to ignore the value of "accesstime" and only
  67.      * look at "modificationtime", that's tvp[1] */
  68.     tv = tvp[1];
  69.  
  70.   tv.tv_sec -= ix_get_gmt_offset();
  71.   /* long-alignment here could be overkill, but with DOS you never know.. */
  72.   ds = alloca (sizeof (struct DateStamp) + 2);
  73.   ds = LONG_ALIGN (ds);
  74.  
  75.   ds->ds_Days   = tv.tv_sec / (24 * 60 * 60);
  76.   /* subtract UNIX/AmigaOS time offset */
  77.   ds->ds_Days  -= 8*365+2;
  78.   tv.tv_sec    %= 24 * 60 * 60;
  79.   ds->ds_Minute = tv.tv_sec / 60;
  80.   tv.tv_sec    %= 60;
  81.   ds->ds_Tick   = (tv.tv_sec * TICKS_PER_SECOND +
  82.                (tv.tv_usec * TICKS_PER_SECOND)/1000000);
  83.  
  84.   result = __plock (name, __utimes_func, ds);
  85.  
  86.   if (! result) errno = __ioerr_to_errno (IoErr ());
  87.   KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  88.  
  89.   return result == -1 ? 0 : -1;
  90. }
  91.