新規記事投稿 フォロー記事投稿 記事のキャンセル
From: にあ <nir@mxa.meshnet.or.jp>
Subject: Re: stat関数の返り値の意味
Date: 1997/07/23 03:21:31
Reference: mesh.program/00352

7月21日に、Puppi☆さんは書きました。

>Perlで、stat関数の13の配列要素の各意味について教えてください。
>特にファイルの最終更新日時についての情報を取得したので、
>
まあ、詳しい解説はマニュアルにゆずるとして、statの13要素の戻し値はUnixの
ファイルシステムに於けるパラメータそのものなので、それ以外のプラットホームに
おいては意味をなさない物も多いです。Unix のマニュアルから抜き出せば、

        dev;    /* ID of device containing a directory entry for this file */
        ino;    /* Inode number */
        mode;   /* File type, attributes, and access control summary */
        nlink;  /* Number of links */
        uid;    /* User ID of file owner */
        gid;    /* Group ID of file group */
        rdev;   /* Device ID; this entry defined only for char or blk spec files */
        size;   /* File size (bytes) */
        atime;  /* Time of last access */
        mtime;  /* Last modification time */
        ctime;  /* Last file status change time */
                /* Measured in secs since 00:00:00 GMT, Jan 1, 1970 */
        blksize;/* Prefered blocksize for file system I/O */
        blocks; /* actual number of blocks allocated */

となりますね。此処でファイルの最終更新日時は文字どおり mtime より得られ、
グリニッジ標準時で1970年1月1日午前0時を起点とする秒数で表わされています。

この時間単位はその他の時間関数と共通ですから、stat() で得られた mtime を
localtime() に与えれば、ファイルの最終更新日時が現地時間で得られるわけです。