Jim Hall wrote:
> > Where can I get a POSIX-compatible utime() for TC?
>
> I wonder if this is what you need:
> http://tools.openoffice.org/source/browse/tools/dmake/msdos/borland/utime.c?rev=1.1.1.1&view=markup
It's not, of course, because it just sets *current* time by writing to
the file.
So I wrote my own version now. Hereby I donate this to the public
domain. ;-)
*** utime.h ***
#ifndef __UTIME_H
#define __UTIME_H
#include <sys/types.h>
struct utimbuf {
time_t actime;
time_t modtime;
};
int utime(const char *path, const struct utimbuf *times);
#endif
***
*** utime.c ***
#include <fcntl.h>
#include <io.h>
#include <time.h>
#include "utime.h"
int
utime(const char *path, const struct utimbuf *times)
{
int fh;
struct tm *tm;
struct ftime ftime;
int rv = 0;
/* DOS needs the file open */
fh = open(path, O_RDONLY);
if (fh == -1) {
return -1;
}
/* DOS stores modification time only */
tm = localtime(×->modtime);
/* convert `tm' to `ftime' structure */
ftime.ft_tsec = tm->tm_sec / 2;
ftime.ft_min = tm->tm_min;
ftime.ft_hour = tm->tm_hour;
ftime.ft_day = tm->tm_mday;
ftime.ft_month = tm->tm_mon + 1;
ftime.ft_year = tm->tm_year - 80;
/* let Borland / Turbo C's `setftime()' do the real work */
rv = setftime(fh, &ftime);
/* close the file */
(void) close(fh);
return rv;
}
***
Robert Riebisch
--
BTTR Software
http://www.bttr-software.de/
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Freedos-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freedos-devel