Ejemplo n.º 1
0
int
utime(const char *name, const struct utimbuf *times)
{
  struct DateStamp stamp;
  unsigned long days, secs;
  time_t time;

  if (times == NULL)
    DateStamp(&stamp);
  else {
    /*
     * AmigaDOS file date is the modification time
     */
    time = times->modtime;

    /*
     * Convert time (secs since 1.1.1970 GMT) to
     * AmigaDOS DateStamp (based on 1.1.1978 local time).
     */
    time -= __local_to_GMT; /* GMT to local */
    days = (unsigned long)time / (unsigned long)(24*60*60);
    secs = (unsigned long)time % (unsigned long)(24*60*60);
    stamp.ds_Days = (LONG)days;
    stamp.ds_Minute = (LONG)(secs / 60);
    stamp.ds_Tick = (LONG)((secs % 60) * TICKS_PER_SECOND);
  }

  if (!SetFileDate((STRPTR)name, &stamp)) {
    set_errno(IoErr());
    return -1;
  }

  return 0;
}
Ejemplo n.º 2
0
bool my_utime (const TCHAR *name, struct mytimeval *tv) {

  struct DateStamp stamp;

  DebOut("name: %s\n", name);

  if(!tv) {
    /* get current time */
    struct DateTime dt;
    DateStamp(&dt.dat_Stamp);
    stamp.ds_Days   = dt.dat_Stamp.ds_Days;
    stamp.ds_Minute = dt.dat_Stamp.ds_Minute;
    stamp.ds_Tick   = dt.dat_Stamp.ds_Tick;
  }
  else {
    /* use supplied time */
    /* NOT TESTED! */
    struct mytimeval tv2;
    tv2.tv_sec = tv->tv_sec;
    tv2.tv_usec = tv->tv_usec;

    timeval_to_amiga (&tv2, &stamp.ds_Days, &stamp.ds_Minute, &stamp.ds_Tick);
  }

  DebOut("stamp.ds_Days: %d\n", stamp.ds_Days);
  DebOut("stamp.ds_Minute: %d\n", stamp.ds_Minute);
  DebOut("stamp.ds_Tick: %d\n", stamp.ds_Tick);

  return SetFileDate(name, &stamp);
}
Ejemplo n.º 3
0
VOID SetFileTimeToFile( CFileItem * item )
{
	ULONG time;
	
	if(!FileTimeToAmiga( item, &time ))
	{
		struct DateStamp ds;
		
		IntToDateStamp( time, &ds );
		
		SetFileDate( item->Name, &ds );
	}
}
Ejemplo n.º 4
0
int main(void)
{
    struct AnchorPath aPath;
    struct RDArgs  *rda;
    IPTR            args[5] = { NULL, NULL, NULL, NULL, FALSE };
    struct DateTime dt;
    LONG            error = 0;
    BPTR            oldCurDir;
    LONG            retval = RETURN_OK;
    BOOL            timeError = FALSE; /* Error in time/date specification? */

    rda = ReadArgs("FILE/A,WEEKDAY,DATE,TIME,ALL/S", args, NULL);

    if(rda == NULL)
    {
	PrintFault(IoErr(), "SetDate");
	return RETURN_FAIL;
    }

    /* Use the current time as default (if no DATE, TIME or WEEKDAY is
       defined) */
    DateStamp(&dt.dat_Stamp);

    dt.dat_Flags   = DTF_FUTURE;
    dt.dat_Format  = FORMAT_DOS;
    dt.dat_StrDate = (TEXT *)args[ARG_DATE];
    dt.dat_StrTime = (TEXT *)args[ARG_TIME];

    /* Change the defaults according to the user's specifications */
    if(StrToDate(&dt))
    {
	dt.dat_StrDate = (TEXT *)args[ARG_WEEKDAY];

	if(!StrToDate(&dt))
	    timeError = TRUE;
    }
    else
	timeError = TRUE;
   
    if(timeError)
    {
	PutStr("SetDate: Illegal DATE or TIME string\n");
	return RETURN_FAIL;
    }


    aPath.ap_Flags = (BOOL)args[ARG_ALL] ? APF_DOWILD : 0;
    aPath.ap_BreakBits = SIGBREAKF_CTRL_C;
    aPath.ap_Strlen = 0;

    /* Save the current dir */
    oldCurDir = CurrentDir(NULL);
    CurrentDir(oldCurDir);

    error = MatchFirst((STRPTR)args[ARG_FILE], &aPath);

    while(error == 0)
    {
	CurrentDir(aPath.ap_Current->an_Lock);

	// VPrintf("%s", (IPTR *)&aPath.ap_Info.fib_FileName);
	
	SetFileDate(aPath.ap_Info.fib_FileName, &dt.dat_Stamp);

	error = MatchNext(&aPath);
    }
    
    MatchEnd(&aPath);

    /* Restore the current dir */
    CurrentDir(oldCurDir);
    
    FreeArgs(rda);

    if(error != ERROR_NO_MORE_ENTRIES)
    {
	if(error == ERROR_BREAK)
	    retval = RETURN_WARN;
	else
	    retval = RETURN_FAIL;

	PrintFault(IoErr(), "SetDate");
    }

    return retval;
}	
Ejemplo n.º 5
0
int main(void)
{
    struct DateTime curr;
    char day[LEN_DATSTRING];
    char time[LEN_DATSTRING];
    char date[LEN_DATSTRING];
    struct DateStamp stamp;

    curr.dat_Format  = FORMAT_DOS;
    curr.dat_Flags   = 0;
    curr.dat_StrDay  = day;
    curr.dat_StrDate = date;
    curr.dat_StrTime = time;  

    DateStamp(&curr.dat_Stamp);
    DateToStr(&curr);
    Printf("Current time: %s, %s, %s\n", day, date, time);
    
    BPTR fh = Open("__TEST__", MODE_NEWFILE);
    
    if (fh != BNULL)
    {
        struct FileInfoBlock *fib = AllocDosObject(DOS_FIB, NULL);
        
        if (fib != NULL)
        {
            if (ExamineFH(fh, fib))
            { 
        	curr.dat_Stamp = fib->fib_Date;
        	DateToStr(&curr);
                Printf("File modification time: %s, %s, %s\n", day, date, time);
            }
            else
        	PrintFault(IoErr(), "Examine failed");

            Printf("Waiting 5 seconds\n");
            Delay(5*50);
            
            DateStamp(&stamp);
            
            Printf("Calling SetFileDate\n");
            if(SetFileDate("__TEST__", &stamp))
            {
                if (ExamineFH(fh, fib))
                { 
                    curr.dat_Stamp = fib->fib_Date;
                    DateToStr(&curr);
                    Printf("New file modification time: %s, %s, %s\n", day, date, time);
                }
                else
                    PrintFault(IoErr(), "Examine failed");        	
            }
            else
        	PrintFault(IoErr(), "SetFileDate");
            
            FreeDosObject(DOS_FIB, fib);
        }
        else 
            PrintFault(IoErr(), "Couldn't alloc FileInfoBlock");
            
        Close(fh);
        DeleteFile("__TEST__");
    }
    else
	PrintFault(IoErr(), "Couldn't create file");
    
    return 0;
}