Test code indentation

2010/06/03

Sample code from jammit rework in linux:

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <mntent.h> // These routines are used to access the file system description file /etc/fstab and the mounted file system description file /etc/mtab
struct mntent *mountpoint(const char *filename, struct mntent *mnt, char *buf, size_t buflen)
{
struct stat s;
FILE *      fp;
dev_t       dev;
if (stat(filename, &s) != 0) {
return NULL;
}
dev = s.st_dev;
if ((fp = setmntent(“/proc/mounts”, “r”)) == NULL) {
return NULL;
}
while (getmntent_r(fp, mnt, buf, buflen)) {
if (stat(mnt->mnt_dir, &s) != 0) {
continue;
}
if (s.st_dev == dev) {
endmntent(fp);
return mnt;
}
}
endmntent(fp);
// Should never reach here.
errno = EINVAL;
return NULL;
}

#include <sys/types.h>#include <sys/stat.h>#include <unistd.h> #include <mntent.h> // These routines are used to access the file system description file /etc/fstab and the mounted file system description file /etc/mtab
struct mntent *mountpoint(const char *filename, struct mntent *mnt, char *buf, size_t buflen){    struct stat s;    FILE *      fp;    dev_t       dev;
if (stat(filename, &s) != 0) {        return NULL;    }
dev = s.st_dev;
if ((fp = setmntent(“/proc/mounts”, “r”)) == NULL) {        return NULL;    }
while (getmntent_r(fp, mnt, buf, buflen)) {        if (stat(mnt->mnt_dir, &s) != 0) {            continue;        }
if (s.st_dev == dev) {            endmntent(fp);            return mnt;        }    }
endmntent(fp);
// Should never reach here.    errno = EINVAL;    return NULL;}

Advertisements

One Response to “Test code indentation”

  1. Mr WordPress Says:

    Hi, this is a comment.
    To delete a comment, just log in, and view the posts’ comments, there you will have the option to edit or delete them.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: