home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / utimes.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  2.6 KB  |  111 lines

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