{"id":3361,"date":"2014-08-07T18:28:27","date_gmt":"2014-08-07T09:28:27","guid":{"rendered":"http:\/\/pchero21.com\/?p=3361"},"modified":"2014-08-07T18:28:27","modified_gmt":"2014-08-07T09:28:27","slug":"utime","status":"publish","type":"post","link":"http:\/\/pchero21.com\/?p=3361","title":{"rendered":"utime"},"content":{"rendered":"<p>utime \uc740 \ud30c\uc77c\uc758 Access time \ubc0f Modification time \uc744 \ubcc0\uacbd\ud560 \ub54c \uc0ac\uc6a9\ud558\ub294 \ud568\uc218\uc774\ub2e4.<\/p>\n<p>\ud2b9\uc815 \ud30c\uc77c \uc815\ub82c\uc744 \ud560 \ub54c, \ud30c\uc77c\uc758 \uc774\ub984\uc744 \ud30c\uc2f1\ud574\uc11c \uc815\ub82c\uc744 \ud558\ub294 \uac83\uc774 \uc544\ub2cc, \ud30c\uc77c\uc758 Modification time \uc744 \uae30\uc900\uc73c\ub85c \uc815\ub82c\uc744 \ud574\uc57c\ud558\ub294 \uacbd\uc6b0\uac00 \uc788\ub2e4.<br \/>\n\uc774\ub7f0 \uacbd\uc6b0, \ud30c\uc77c \uc791\uc5c5 \uc774\ud6c4\uc5d0\ub3c4 \uc774\uc804\uc758 Modification time \uc744 \uc720\uc9c0\ud574\uc57c \ud558\ub294 \uacbd\uc6b0\uac00 \uc788\ub294\ub370,<\/p>\n<p>\uc774\ub7f0 \uacbd\uc6b0, utime \uc744 \uc0ac\uc6a9\ud558\uba74 \ud3b8\ub9ac\ud558\ub2e4.<\/p>\n<p>&nbsp;<\/p>\n<p>utime \uc740 input \uc778\uc790\ub85c utimebuf \ub77c\ub294 \uad6c\uc870\uccb4\ub97c \uc0ac\uc6a9\ud55c\ub2e4. utime \uc744 \uc774\uc6a9\ud558\uba74 access time \uacfc modification time \uc744 \uc218\uc815\ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre class=\"brush:cpp\">struct utimbuf {\r\n    time_t actime;       \/* access time *\/\r\n    time_t modtime;      \/* modification time *\/\r\n};<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>SYNOPSIS<\/strong><\/p>\n<blockquote><p>#include &lt;sys\/types.h&gt;<br \/>\n#include &lt;utime.h&gt;<\/p>\n<p>int utime(const char *filename, const struct utimbuf *times);<\/p>\n<p>#include &lt;sys\/time.h&gt;<\/p>\n<p>int utimes(const char *filename, const struct timeval times[2])<\/p><\/blockquote>\n<p><strong>\uc0d8\ud50c \ucf54\ub4dc<\/strong><\/p>\n<pre class=\"brush:cpp\">\/*\r\n * main.c\r\n * \r\n * Copyright 2014 Sungtae Kim &lt;pchero21@gmail.com&gt;\r\n * \r\n * This program is free software; you can redistribute it and\/or modify\r\n * it under the terms of the GNU General Public License as published by\r\n * the Free Software Foundation; either version 2 of the License, or\r\n * (at your option) any later version.\r\n * \r\n * This program is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r\n * GNU General Public License for more details.\r\n * \r\n * You should have received a copy of the GNU General Public License\r\n * along with this program; if not, write to the Free Software\r\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,\r\n * MA 02110-1301, USA.\r\n * \r\n * \r\n *\/\r\n\r\n\r\n#include &lt;stdio.h&gt;\r\n#include &lt;sys\/types.h&gt;\r\n#include &lt;sys\/stat.h&gt;\r\n#include &lt;unistd.h&gt;\r\n#include &lt;utime.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n#include &lt;time.h&gt;\r\n\r\nvoid file_stat(struct stat sb);\r\n\r\n\r\nint main(int argc, char **argv)\r\n{\r\n    struct stat sb[2];\r\n    int i;\r\n\r\n    if (argc != 3) {\r\n       fprintf(stderr, \"Usage: %s &lt;pathname&gt;\\n\", argv[0]);\r\n       exit(EXIT_FAILURE);\r\n    }\r\n    \r\n    printf(\"Before utime-----------------------------------\\n\");\r\n    for(i = 0; i &lt; 2; i++)\r\n    {\r\n        if (stat(argv[i + 1], &amp;sb[i]) == -1) {\r\n            perror(\"stat\");\r\n            exit(EXIT_FAILURE);\r\n        }\r\n\r\n        file_stat(sb[i]);\r\n        printf(\"--------\\n\");\r\n    }\r\n    \r\n    struct utimbuf ubuf;\r\n    ubuf.actime = sb[0].st_atime;\r\n    ubuf.modtime = sb[0].st_mtime;\r\n\r\n    \/\/ Let's use utime!\r\n    utime(argv[2], &amp;ubuf);\r\n\r\n    printf(\"\\n\\nAfter utime-----------------------------------\\n\");\r\n    for(i = 0; i &lt; 2; i++)\r\n    {\r\n        if (stat(argv[i + 1], &amp;sb[i]) == -1) {\r\n            perror(\"stat\");\r\n            exit(EXIT_FAILURE);\r\n        }\r\n        file_stat(sb[i]);\r\n        printf(\"--------\\n\");\r\n    }\r\n\r\n    return 0;\r\n}\r\n\r\n\r\nvoid file_stat(struct stat sb)\r\n{\r\n    switch (sb.st_mode &amp; S_IFMT) {\r\n        case S_IFBLK:  printf(\"block device\\n\");            break;\r\n        case S_IFCHR:  printf(\"character device\\n\");        break;\r\n        case S_IFDIR:  printf(\"directory\\n\");               break;\r\n        case S_IFIFO:  printf(\"FIFO\/pipe\\n\");               break;\r\n        case S_IFLNK:  printf(\"symlink\\n\");                 break;\r\n        case S_IFREG:  printf(\"regular file\\n\");            break;\r\n        case S_IFSOCK: printf(\"socket\\n\");                  break;\r\n        default:       printf(\"unknown?\\n\");                break;\r\n    }\r\n    \r\n    printf(\"I-node number:            %ld\\n\", (long) sb.st_ino);\r\n\r\n    printf(\"Mode:                     %lo (octal)\\n\",\r\n           (unsigned long) sb.st_mode);\r\n\r\n    printf(\"Link count:               %ld\\n\", (long) sb.st_nlink);\r\n    printf(\"Ownership:                UID=%ld   GID=%ld\\n\",\r\n           (long) sb.st_uid, (long) sb.st_gid);\r\n\r\n    printf(\"Preferred I\/O block size: %ld bytes\\n\",\r\n           (long) sb.st_blksize);\r\n    printf(\"File size:                %lld bytes\\n\",\r\n           (long long) sb.st_size);\r\n    printf(\"Blocks allocated:         %lld\\n\",\r\n           (long long) sb.st_blocks);\r\n\r\n    printf(\"Last status change:       %s\", ctime(&amp;sb.st_ctime));\r\n    printf(\"Last file access:         %s\", ctime(&amp;sb.st_atime));\r\n    printf(\"Last file modification:   %s\", ctime(&amp;sb.st_mtime));\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>\uacb0\uacfc<\/strong><\/p>\n<pre class=\"brush:shell\">pchero@MyGalaxy:~\/workspace\/Study\/Program\/file\/stat_example$ .\/main .\/test.txt test2.txt \r\nBefore utime-----------------------------------\r\nregular file\r\nI-node number:            12976592\r\nMode:                     100664 (octal)\r\nLink count:               1\r\nOwnership:                UID=1000   GID=1000\r\nPreferred I\/O block size: 4096 bytes\r\nFile size:                0 bytes\r\nBlocks allocated:         0\r\nLast status change:       Thu Aug  7 11:08:25 2014\r\nLast file access:         Thu Aug  7 10:56:34 2014\r\nLast file modification:   Thu Aug  7 10:56:34 2014\r\n--------\r\nregular file\r\nI-node number:            12976593\r\nMode:                     100664 (octal)\r\nLink count:               1\r\nOwnership:                UID=1000   GID=1000\r\nPreferred I\/O block size: 4096 bytes\r\nFile size:                0 bytes\r\nBlocks allocated:         0\r\nLast status change:       Thu Aug  7 11:11:53 2014\r\nLast file access:         Thu Aug  7 11:11:53 2014\r\nLast file modification:   Thu Aug  7 11:11:53 2014\r\n--------\r\n\r\n\r\nAfter utime-----------------------------------\r\nregular file\r\nI-node number:            12976592\r\nMode:                     100664 (octal)\r\nLink count:               1\r\nOwnership:                UID=1000   GID=1000\r\nPreferred I\/O block size: 4096 bytes\r\nFile size:                0 bytes\r\nBlocks allocated:         0\r\nLast status change:       Thu Aug  7 11:08:25 2014\r\nLast file access:         Thu Aug  7 10:56:34 2014\r\nLast file modification:   Thu Aug  7 10:56:34 2014\r\n--------\r\nregular file\r\nI-node number:            12976593\r\nMode:                     100664 (octal)\r\nLink count:               1\r\nOwnership:                UID=1000   GID=1000\r\nPreferred I\/O block size: 4096 bytes\r\nFile size:                0 bytes\r\nBlocks allocated:         0\r\nLast status change:       Thu Aug  7 11:12:01 2014\r\nLast file access:         Thu Aug  7 10:56:34 2014\r\nLast file modification:   Thu Aug  7 10:56:34 2014\r\n--------\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>utime \uc740 \ud30c\uc77c\uc758 Access time \ubc0f Modification time \uc744 \ubcc0\uacbd\ud560 \ub54c \uc0ac\uc6a9\ud558\ub294 \ud568\uc218\uc774\ub2e4. \ud2b9\uc815 \ud30c\uc77c \uc815\ub82c\uc744 \ud560 \ub54c, \ud30c\uc77c\uc758 \uc774\ub984\uc744 \ud30c\uc2f1\ud574\uc11c \uc815\ub82c\uc744 \ud558\ub294 \uac83\uc774 \uc544\ub2cc, \ud30c\uc77c\uc758 Modification time \uc744 \uae30\uc900\uc73c\ub85c \uc815\ub82c\uc744 \ud574\uc57c\ud558\ub294 \uacbd\uc6b0\uac00 \uc788\ub2e4. \uc774\ub7f0 \uacbd\uc6b0, \ud30c\uc77c \uc791\uc5c5 \uc774\ud6c4\uc5d0\ub3c4 \uc774\uc804\uc758 &hellip; <a href=\"http:\/\/pchero21.com\/?p=3361\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[825,832],"_links":{"self":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/posts\/3361"}],"collection":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3361"}],"version-history":[{"count":8,"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/posts\/3361\/revisions"}],"predecessor-version":[{"id":3369,"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/posts\/3361\/revisions\/3369"}],"wp:attachment":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3361"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}