BarryServer : Git

All the code for all my projects
// BarryServer : Git / OrionUserland / commit / 2e110925c3be315a94bfbf15cecbdaa0746bfe32 / ls

// Related

OrionUserland

Barry Using POSIX names in structs 2e11092 (2 years, 4 months ago)
diff --git a/ls/main.c b/ls/main.c
index 27b754c..54fab25 100644
--- a/ls/main.c
+++ b/ls/main.c
@@ -93,9 +93,9 @@ print_normal(Result *head)
 		next = curr->next;
 
 		int executable = 0;
-		if ((curr->stat.mode & S_IXUSR)
-		 || (curr->stat.mode & S_IXGRP)
-		 || (curr->stat.mode & S_IXOTH))
+		if ((curr->stat.st_mode & S_IXUSR)
+		 || (curr->stat.st_mode & S_IXGRP)
+		 || (curr->stat.st_mode & S_IXOTH))
 			executable = 1;
 
 		if (curr->type == DT_DIR)
@@ -134,26 +134,26 @@ print_long(Result *head)
 	size_t total = 0;
 	int linkWidth = 0, unameWidth = 0, groupWidth = 0, sizeWidth = 0;
 	for (curr = head; curr; curr = curr->next) {
-		int linkTmp = curr->stat.nlink, linkWidthTmp = 1;
+		int linkTmp = curr->stat.st_nlink, linkWidthTmp = 1;
 		while (linkTmp /= 10)
 			linkWidthTmp++;
 		if (linkWidthTmp > linkWidth)
 			linkWidth = linkWidthTmp;
 
-		Passwd *pwd = getpwuid(curr->stat.uid);
-		if (strlen(pwd->username) > unameWidth)
-			unameWidth = strlen(pwd->username);
-		Group *grp = getgrgid(curr->stat.gid);
-		if (strlen(grp->name) > groupWidth)
-			groupWidth = strlen(grp->name);
+		Passwd *pwd = getpwuid(curr->stat.st_uid);
+		if (strlen(pwd->pw_name) > unameWidth)
+			unameWidth = strlen(pwd->pw_name);
+		Group *grp = getgrgid(curr->stat.st_gid);
+		if (strlen(grp->gr_name) > groupWidth)
+			groupWidth = strlen(grp->gr_name);
 
-		int sizeTmp = curr->stat.size, sizeWidthTmp = 1;
+		int sizeTmp = curr->stat.st_size, sizeWidthTmp = 1;
 		while (sizeTmp /= 10)
 			sizeWidthTmp++;
 		if (sizeWidthTmp > sizeWidth)
 			sizeWidth = sizeWidthTmp;
 
-		total += (curr->stat.size + (1024 - 1)) / 1024;
+		total += (curr->stat.st_size + (1024 - 1)) / 1024;
 	}
 
 	/* Print out */
@@ -167,27 +167,27 @@ print_long(Result *head)
 		char uname[33], group[33];
 		int executable = 0;
 		perm[0] = type[curr->type];
-		perm[1] = (curr->stat.mode & S_IRUSR) ? 'r' : '-';
-		perm[2] = (curr->stat.mode & S_IWUSR) ? 'w' : '-';
-		perm[3] = (curr->stat.mode & S_IXUSR) ? 'x' : '-';
-		perm[4] = (curr->stat.mode & S_IRGRP) ? 'r' : '-';
-		perm[5] = (curr->stat.mode & S_IWGRP) ? 'w' : '-';
-		perm[6] = (curr->stat.mode & S_IXGRP) ? 'x' : '-';
-		perm[7] = (curr->stat.mode & S_IROTH) ? 'r' : '-';
-		perm[8] = (curr->stat.mode & S_IWOTH) ? 'w' : '-';
-		perm[9] = (curr->stat.mode & S_IXOTH) ? 'x' : '-';
-		Passwd *pwd = getpwuid(curr->stat.uid);
-		Group *grp = getgrgid(curr->stat.gid);
-		if ((curr->stat.mode & S_IXUSR)
-		 || (curr->stat.mode & S_IXGRP)
-		 || (curr->stat.mode & S_IXOTH))
+		perm[1] = (curr->stat.st_mode & S_IRUSR) ? 'r' : '-';
+		perm[2] = (curr->stat.st_mode & S_IWUSR) ? 'w' : '-';
+		perm[3] = (curr->stat.st_mode & S_IXUSR) ? 'x' : '-';
+		perm[4] = (curr->stat.st_mode & S_IRGRP) ? 'r' : '-';
+		perm[5] = (curr->stat.st_mode & S_IWGRP) ? 'w' : '-';
+		perm[6] = (curr->stat.st_mode & S_IXGRP) ? 'x' : '-';
+		perm[7] = (curr->stat.st_mode & S_IROTH) ? 'r' : '-';
+		perm[8] = (curr->stat.st_mode & S_IWOTH) ? 'w' : '-';
+		perm[9] = (curr->stat.st_mode & S_IXOTH) ? 'x' : '-';
+		Passwd *pwd = getpwuid(curr->stat.st_uid);
+		Group *grp = getgrgid(curr->stat.st_gid);
+		if ((curr->stat.st_mode & S_IXUSR)
+		 || (curr->stat.st_mode & S_IXGRP)
+		 || (curr->stat.st_mode & S_IXOTH))
 			executable = 1;
 
 		printf("%s %*d %*s %*s %*d ", perm,
-		       linkWidth, curr->stat.nlink,
-		       -unameWidth, pwd->username,
-		       -groupWidth, grp->name,
-		       sizeWidth, curr->stat.size);
+		       linkWidth, curr->stat.st_nlink,
+		       -unameWidth, pwd->pw_name,
+		       -groupWidth, grp->gr_name,
+		       sizeWidth, curr->stat.st_size);
 
 		if (curr->type == DT_DIR)
 			printf("\033[1;34m%s\033[0m\n", curr->name);
@@ -232,7 +232,7 @@ ls(char *name)
 	}
 
 	stat(name, &statbuf);
-	if (!S_ISDIR(statbuf.mode)) {
+	if (!S_ISDIR(statbuf.st_mode)) {
 		close(fd);
 		return;
 	}
@@ -245,17 +245,17 @@ ls(char *name)
 	sz = getdents(fd, buf, 512);
 	for (de = (void *) buf;
 	     de < (struct dirent *) (buf + sz);
-	     de = (void *) de + de->namelen + sizeof(struct dirent)) {
-		if (de->name[0] == '.' && !allFlag)
+	     de = (void *) de + de->d_namelen + sizeof(struct dirent)) {
+		if (de->d_name[0] == '.' && !allFlag)
 			continue;
 		curr = malloc(sizeof(Result));
 		curr->next = NULL;
 		curr->prev = prev;
-		curr->ino = de->ino;
-		curr->type = de->type;
-		curr->namelen = de->namelen;
-		memcpy(curr->name, de->name, de->namelen);
-		curr->name[de->namelen] = '\0';
+		curr->ino = de->d_ino;
+		curr->type = de->d_type;
+		curr->namelen = de->d_namelen;
+		memcpy(curr->name, de->d_name, de->d_namelen);
+		curr->name[de->d_namelen] = '\0';
 		stat(curr->name, &curr->stat);
 		if (prev)
 			prev->next = curr;