comparison src/file-io.cc @ 1377:44f5d41ff757

[project @ 1995-09-12 00:07:58 by jwe]
author jwe
date Tue, 12 Sep 1995 00:08:47 +0000
parents ed5757e3333b
children e29697484908
comparison
equal deleted inserted replaced
1376:b5e74064566f 1377:44f5d41ff757
56 #include "error.h" 56 #include "error.h"
57 #include "file-io.h" 57 #include "file-io.h"
58 #include "help.h" 58 #include "help.h"
59 #include "input.h" 59 #include "input.h"
60 #include "mappers.h" 60 #include "mappers.h"
61 #include "oct-map.h"
61 #include "octave-hist.h" 62 #include "octave-hist.h"
62 #include "pager.h" 63 #include "pager.h"
63 #include "statdefs.h" 64 #include "statdefs.h"
64 #include "sysdep.h" 65 #include "sysdep.h"
65 #include "syswait.h" 66 #include "syswait.h"
66 #include "tree-const.h" 67 #include "tree-const.h"
67 #include "utils.h" 68 #include "utils.h"
68 #include "variables.h" 69 #include "variables.h"
70
71 extern "C"
72 {
73 #include <readline/tilde.h>
74 }
69 75
70 // keeps a count of args sent to printf or scanf 76 // keeps a count of args sent to printf or scanf
71 static int fmt_arg_count = 0; 77 static int fmt_arg_count = 0;
72 78
73 // double linked list containing relevant information about open files 79 // double linked list containing relevant information about open files
2443 retval = unlink_internal (args); 2449 retval = unlink_internal (args);
2444 2450
2445 return retval; 2451 return retval;
2446 } 2452 }
2447 2453
2454 static Octave_map
2455 mk_stat_map (struct stat& st)
2456 {
2457 Octave_map m;
2458
2459 m["dev"] = (double) st.st_dev;
2460 m["ino"] = (double) st.st_ino;
2461 m["mode"] = (double) st.st_mode;
2462 m["nlink"] = (double) st.st_nlink;
2463 m["uid"] = (double) st.st_uid;
2464 m["gid"] = (double) st.st_gid;
2465 #if defined (HAVE_ST_RDEV)
2466 m["rdev"] = (double) st.st_rdev;
2467 #endif
2468 m["size"] = (double) st.st_size;
2469 m["atime"] = (double) st.st_atime;
2470 m["mtime"] = (double) st.st_mtime;
2471 m["ctime"] = (double) st.st_ctime;
2472 #if defined (HAVE_ST_BLKSIZE)
2473 m["blksize"] = (double) st.st_blksize;
2474 #endif
2475 #if defined (HAVE_ST_BLOCKS)
2476 m["blocks"] = (double) st.st_blocks;
2477 #endif
2478
2479 return m;
2480 }
2481
2482 DEFUN ("stat", Fstat, Sstat, 1, 1,
2483 "stat (NAME)\n\
2484 \n\
2485 Given the name of a file, return a structure with the following
2486 elements:\n\
2487 \n\
2488 dev : id of device containing a directory entry for this file\n\
2489 ino : file number of the file\n\
2490 mode : file mode, as an integer\n\
2491 nlink : number of links\n\
2492 uid : user id of file's owner\n\
2493 gid : group id of file's group \n\
2494 rdev : id of device for block or character special files\n\
2495 size : size in bytes\n\
2496 atime : time of last access\n\
2497 mtime : time of last modification\n\
2498 ctime : time of last file status change\n\
2499 blksize : size of blocks in the file\n\
2500 blocks : number of blocks allocated for file\n\
2501 \n\
2502 If the file does not exist, -1 is returned.")
2503 {
2504 Octave_object retval;
2505
2506 if (args.length () == 1)
2507 {
2508 const char *name = args(0).string_value ();
2509
2510 static char *fname = 0;
2511
2512 if (fname)
2513 free (fname);
2514
2515 fname = tilde_expand (name);
2516
2517 if (! error_state)
2518 {
2519 struct stat buf;
2520
2521 if (stat (fname, &buf) < 0)
2522 retval = -1.0;
2523 else
2524 retval = tree_constant (mk_stat_map (buf));
2525 }
2526 }
2527 else
2528 print_usage ("stat");
2529
2530 return retval;
2531 }
2532
2448 /* 2533 /*
2449 ;;; Local Variables: *** 2534 ;;; Local Variables: ***
2450 ;;; mode: C++ *** 2535 ;;; mode: C++ ***
2451 ;;; page-delimiter: "^/\\*" *** 2536 ;;; page-delimiter: "^/\\*" ***
2452 ;;; End: *** 2537 ;;; End: ***