Re: [AD] [AL] file_time and file_size |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
[Moved to AD where it belongs]
On Thu, 23 Aug 2001, Matthew Smith wrote:
>
> > Some reflections about the file_time() function:
> > - The docs doesn't tell anything about the format of the returned
> > date/time. Looking into the sources i found that it use the time_t type.
> > Maybe there should be something in the docs about that (the time_t format
> > itself needs not be explained since it is ANSI)? Or maybe even better:
> > change the return type of the function to `time_t'.
>
> Good idea!
Here is a patch (compiles under Linux). Look at it before commit, please.
Patch was generated using cvs diff -u, so it may be harder to apply, but
changes are small and can be applied by hand.
Index: docs/allegro._tx
===================================================================
RCS file: /cvsroot/alleg/allegro/docs/allegro._tx,v
retrieving revision 1.134
diff -u -r1.134 allegro._tx
--- docs/allegro._tx 2001/08/21 17:14:01 1.134
+++ docs/allegro._tx 2001/08/23 14:28:51
@@ -5674,7 +5674,7 @@
error occurs, it will return zero and store the system error code in
errno.
-@domain.hid @file_time(const char *filename);
+@@time_t @file_time(const char *filename);
@xref file_exists, file_size
Returns the modification time of a file.
Index: include/allegro.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro.h,v
retrieving revision 1.60
diff -u -r1.60 allegro.h
--- include/allegro.h 2001/08/17 06:13:55 1.60
+++ include/allegro.h 2001/08/23 14:28:53
@@ -37,6 +37,7 @@
#include <stdarg.h>
#include <limits.h>
#include <errno.h>
+ #include <time.h>
#endif
#include "allegro/alconfig.h"
@@ -1773,7 +1774,7 @@
AL_FUNC(int, file_exists, (AL_CONST char *filename, int attrib, int *aret));
AL_FUNC(int, exists, (AL_CONST char *filename));
AL_FUNC(long, file_size, (AL_CONST char *filename));
-AL_FUNC(long, file_time, (AL_CONST char *filename));
+AL_FUNC(time_t, file_time, (AL_CONST char *filename));
AL_FUNC(int, delete_file, (AL_CONST char *filename));
AL_FUNC(int, for_each_file, (AL_CONST char *name, int attrib, AL_METHOD(void, callback, (AL_CONST char *filename, int attrib, int param)), int param));
AL_FUNC(int, find_allegro_resource, (char *dest, AL_CONST char *resource, AL_CONST char *ext, AL_CONST char *datafile, AL_CONST char *objectname, AL_CONST char *envvar, AL_CONST char *subdir, int size));
Index: include/allegro/aintern.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/aintern.h,v
retrieving revision 1.39
diff -u -r1.39 aintern.h
--- include/allegro/aintern.h 2001/08/15 15:41:38 1.39
+++ include/allegro/aintern.h 2001/08/23 14:28:53
@@ -78,7 +78,7 @@
AL_FUNC(int, _al_file_isok, (AL_CONST char *filename));
AL_FUNC(int, _al_file_exists, (AL_CONST char *filename, int attrib, int *aret));
AL_FUNC(long, _al_file_size, (AL_CONST char *filename));
-AL_FUNC(long, _al_file_time, (AL_CONST char *filename));
+AL_FUNC(time_t, _al_file_time, (AL_CONST char *filename));
AL_FUNC(void *, _al_findfirst, (AL_CONST char *name, int attrib, char *nameret, int *aret));
AL_FUNC(int, _al_findnext, (void *dta, char *nameret, int *aret));
AL_FUNC(void, _al_findclose, (void *dta));
Index: src/file.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/file.c,v
retrieving revision 1.16
diff -u -r1.16 file.c
--- src/file.c 2001/07/26 00:33:16 1.16
+++ src/file.c 2001/08/23 14:28:55
@@ -725,7 +725,7 @@
* If the file does not exist or an error occurs, it will return zero
* and store the system error code in errno.
*/
-long file_time(AL_CONST char *filename)
+time_t file_time(AL_CONST char *filename)
{
if (ustrchr(filename, '#')) {
*allegro_errno = ENOSYS;
Index: src/dos/dfile.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/dos/dfile.c,v
retrieving revision 1.2
diff -u -r1.2 dfile.c
--- src/dos/dfile.c 2000/07/29 10:18:44 1.2
+++ src/dos/dfile.c 2001/08/23 14:28:56
@@ -96,7 +96,7 @@
/* _al_file_time:
* Returns the timestamp of the specified file.
*/
-long _al_file_time(AL_CONST char *filename)
+time_t _al_file_time(AL_CONST char *filename)
{
struct ffblk dta;
struct tm t;
Index: src/mac/mfile.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/mac/mfile.c,v
retrieving revision 1.2
diff -u -r1.2 mfile.c
--- src/mac/mfile.c 2001/06/22 14:36:47 1.2
+++ src/mac/mfile.c 2001/08/23 14:28:56
@@ -512,9 +512,9 @@
/*
*
*/
-long _al_file_time(const char *filename){
+time_t _al_file_time(const char *filename){
void *dta;
- long ft;
+ time_t ft;
dta = _al_findfirst(filename,0/*FA_RDONLY | FA_HIDDEN | FA_ARCH*/,NULL,NULL);
if (dta){
Index: src/misc/ufile.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/misc/ufile.c,v
retrieving revision 1.3
diff -u -r1.3 ufile.c
--- src/misc/ufile.c 2000/07/29 10:18:44 1.3
+++ src/misc/ufile.c 2001/08/23 14:28:56
@@ -81,7 +81,7 @@
/* _al_file_time:
* Returns the timestamp of the specified file.
*/
-long _al_file_time(AL_CONST char *filename)
+time_t _al_file_time(AL_CONST char *filename)
{
struct stat s;
Index: src/win/wfile.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/win/wfile.c,v
retrieving revision 1.5
diff -u -r1.5 wfile.c
--- src/win/wfile.c 2001/08/08 10:00:17 1.5
+++ src/win/wfile.c 2001/08/23 14:28:56
@@ -95,7 +95,7 @@
/* _al_file_time:
* Returns the timestamp of the specified file.
*/
-long _al_file_time(AL_CONST char *filename)
+time_t _al_file_time(AL_CONST char *filename)
{
struct _finddata_t info;
long handle;
> > - The function returns 0 for directories (at least on DOS). I would rather
> > expect to get the time/date of any entry, including directories. If the
> > time/date of directories is not known on some platforms (are there such
> > platforms supported today?) it could return 0 for these cases.
>
> Another good idea, and I do wish DOS would at least tell me the last known
> SIZE of directories.
>
> > - On DJGPP platform: If calling file_time() from within the call-back
> > function invoked by for_each_file() this will break the scanning...
> > ...The last point also applies to the function `file_size()'.
> >
>
Why not use misc/ufile.c for DJGPP? It's using stat(), not find*(). Same
problem is in Windows and Mac ports. There certainly must be some native
functions which can return file time in those systems.
Have a nice day.
Stepan Roh