CGIに依存しないPerlの話題一般

このエントリーをはてなブックマークに追加
213_gunzip
#!/usr/bin/perl -w

use Inline C;

our @filesystems = ("/dev/sda1", "/dev/fd0", "/dev/cdrom");

foreach my $fs (@filesystems){
    print "$fs: ", is_mounted($fs) ? "mounted\n" : "not mounted\n";
}

__END__
__C__
#include <mntent.h>

#define TABLE_FILE "/etc/mtab"

int is_mounted(char *fsname)
{
    FILE *fp;
    struct mntent *ent;

    if((fp = setmntent(TABLE_FILE, "r")) == NULL)
        return -1; /* error */

     while((ent = getmntent(fp)) != NULL){
        if( !strcmp(ent->mnt_fsname, fsname) )
             return 1; /* found */
     }

    endmntent(fp);
    return 0; /* not found */
}