🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fj.lang.c
Article #651

dirent.d_name

#651
From: Toshiya Andoh
Date: Fri, 27 Mar 1998 00:00
49 lines
1934 bytes

安藤@富士通NCSと申します。

ディレクトリ内のサブディレクトリ名を取得するためのプログラムを、
solaris 1.x系で作成し、それをsolaris 2.x系でも動かそうとしました。

ところが、readdirで得られる、dirent内のファイル名の情報が頭2byte
削られて表示されました。
# 実際には、ファイル名が2byteずれて格納されていました。

これは、OSのバグでしょうか、
それともコンパイルの仕方(オプションは指定してません)が悪いのでしょうか。

回答よろしくお願いします。

うまくいった環境:
SunOS 4.1.3-JLE1.1.3 + SUN SPARC C Compiler
SunOS 4.1.4-JL       + SUN SPARC C Compiler
solaris 2.4          + SUN SPARC C Compiler
solaris 2.4          + gcc
solaris 2.5          + gcc
solaris 2.6          + gcc

うまくいかなかった環境:
solaris 2.5          + SUN SPARC C Compiler
solaris 2.6          + SUN SPARC C Compiler

------------------------------------------------------
#include <stdio.h>
#include <dirent.h>

main()
{
    DIR *dirp;
    struct dirent *direntp;

    dirp = opendir( "." );
    while ( (direntp = readdir( dirp )) != NULL )
        (void)printf( "%s\n", direntp->d_name );
    (void)closedir( dirp );
    return (0);
}

--
富士通名古屋通信システム(株)  システムエンジニアリング部
〇氏名  :安藤  俊也
〇TEL   :052-952-8914
〇E-mail:andou@ncs.ts.fujitsu.co.jp
Technical Details
Message-ID: <NEWTNews.890963246.4368.andou@andou.ncs.ts.fujitsu.co.jp>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: Japanese,JIS
X-Google-Thread: 106434,d2ace75549f088b0,start
X-Google-Attributes: gid106434,public
From: Toshiya Andoh <andou@ncs.ts.fujitsu.co.jp>
Subject: dirent.d_name
Date: 1998/03/27
Message-ID: <NEWTNews.890963246.4368.andou@andou.ncs.ts.fujitsu.co.jp>
X-Deja-AN: 338098445
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; CHARSET=ISO-2022-JP
Organization: Fujitsu Nagoya Communication Systems Limited
Newsgroups: fj.lang.c