LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 891|回复: 3

帮我看一下utime

[复制链接]
发表于 2006-2-28 16:11:43 | 显示全部楼层 |阅读模式
#include <stdio.h>
#include <time.h>
#include <utime.h>
#include <sys/types.h>

#include <sys/stat.h>
#include <fcntl.h>
//#include <sys/time.h>

int
main (int argc, char **argv)
{

  int i;
  struct stat statbuf;
  struct utimebuf mytimebuf;


  if (argc < 1)
    {
      fprintf (stderr, "Usage: %s  argv", argv[0]);
      exit (1);
    }
  else
    {




      for (i = 1; i < argc; i++)
        {

          if (stat (argv, &statbuf) < 0)
            {
              fprintf (stderr, "%s: stat error ", argv);
              continue;
            }

          if (open (argv, O_RDWR | O_TRUNC) < 0)
            {
              fprintf (stderr, "%spen error", argv);
              continue;

            }
          mytimebuf.actime = statbuf.st_atime;
          mytimebuf.modtime = statbuf.st_mtime;
          if (utime (argv, &mytimebuf) < 0)
            {
              fprintf (stderr, "%s:utime error", argv);
              continue;
            }


        }

      exit (0);


    }


}

when I compile the code with gcc , gcc says:
utime.c: In function `main':
utime.c:16: error: storage size of `mytimebuf' isn't known
I  try  several times ,but still that , how to solve the problem?
发表于 2006-2-28 17:01:12 | 显示全部楼层
都不知到看什么
回复 支持 反对

使用道具 举报

发表于 2006-2-28 19:20:56 | 显示全部楼层
gcc 的错误信息已经说得很清楚了.
是 struct utimbuf, 而不是 struct utimebuf.

参看 utime(2).

另外, 不要那么懒, 也不要那么粗心. 一般情况下,
man -k 加 man 可以解决 90% 的问题, 再加上
网上搜索就可以解决 99% 的问题.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-1 10:53:58 | 显示全部楼层
老兄教育得极是, 我太粗心了,希望以后绝不要发生。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表