stat 시스템호출에관하여...

koddakgi의 이미지

readdir() 루프를 돌면서
stat()를 호출하여 파일의 정보를 읽어서 저장하는 프로그램입니다.
처음실행하면 잘 읽어서 처리합니다.
그런데 디렉토리내 하나의파일이름을 mv한후 실행하면
파일을 찾을수 없다는 에러가 발생합니다.
그래서 stat()의 첫번째 인자로 전체경로를 주었더니 잘돌아 가더군요
원인을 알고 싶습니다.
아래는 수정한후 소스입니다.

    while(d = readdir(dp))
    {
        /* i-node 유효한것만 */
        if(d->d_ino < 1 ) continue;
        
        /* 파일의 전체경로로 수정  */
        sprintf(sFull,"%s/%s/%s",isJobDir,ptDir->sDirName,d->d_name);
        
        /* if( stat(d->d_name,&stb) == -1 ) */

         /* 상태정보획득 */
        if( stat(sFull,&stb) == -1 )
        {
            sprintf(isErrMsg,"%d:%s stat fail %d",__LINE__,d->d_name,errno);
            return (FALSE);
        }
        /* 디렉토리는 제외 */
        if( S_ISDIR(stb.st_mode) ) continue;

        /* printf(" info [%s][%d]\n", d->d_name, stb.st_size); */


        /* 상태정보저장 */
        strncpy(ptDir->pFileList[i].sName, d->d_name,
                                  sizeof(ptDir->pFileList[i].sName));
        ptDir->pFileList[i].st_atim = stb.st_atime;
        ptDir->pFileList[i].st_mtim = stb.st_mtime;
        ptDir->pFileList[i].st_ctim = stb.st_ctime;
        ptDir->pFileList[i].st_size = stb.st_size;
        i++;
    }
cinsk의 이미지

readdir(3)은 주어진 디렉토리 안의 파일 이름을 알려 주지요.. 예를 들어 A라는 디렉토리에 a, b, c라는 파일이 있었다면, a, b, c를 돌려 주겠지요.

이때 readdir(3)의 결과에 바로 stat(2)을 때리면 당연 파일이 없다고 에러가 나지요.. stat(2)에 줄 첫 번째 인자를 a, b, c로 주면 안되지요.. A/a, A/b, A/c로 주어야 하겠지요.

그리고 어떤 프로그램인지는 잘 모르겠지만, 이식성(portability)을 생각한다면 struct dirent의 멤버들 중 d_name을 제외한 나머지는 쓰면 안되지요.. OS마다 다르기 때문이죠..

쓰고 보니 말투가 이상하군.. -_-;

koddakgi의 이미지

그걸 미처 생각하지 못했군요
A/a로 함 배보구 결과를 말씀드리지요.
이식성은 별루 중요치 않습니다.
생성시간 및 수정시간은 걍 display 할려구 저장합니다.
필요한건 파일의 사이즈입니다.

여자는 도대체 무엇으로 사는가?

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.