Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSEP551
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Krishna Vinnakota
CSEP551
Commits
3dcf889c
Commit
3dcf889c
authored
17 years ago
by
rsc
Browse files
Options
Downloads
Patches
Plain Diff
cleanup
parent
6bf2e5c8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ls.c
+12
-14
12 additions, 14 deletions
ls.c
with
12 additions
and
14 deletions
ls.c
+
12
−
14
View file @
3dcf889c
...
...
@@ -3,10 +3,6 @@
#include
"user.h"
#include
"fs.h"
char
buf
[
512
];
struct
stat
st
;
struct
dirent
dirent
;
void
pname
(
char
*
n
)
{
...
...
@@ -22,10 +18,11 @@ pname(char *n)
int
main
(
int
argc
,
char
*
argv
[])
{
char
buf
[
512
],
*
p
;
int
fd
;
uint
off
;
ui
nt
sz
;
char
*
p
;
uint
off
,
sz
;
struct
dire
nt
de
;
struct
stat
st
;
if
(
argc
>
2
){
puts
(
"Usage: ls [dir]
\n
"
);
...
...
@@ -58,12 +55,12 @@ main(int argc, char *argv[])
break
;
case
T_DIR
:
sz
=
st
.
size
;
for
(
off
=
0
;
off
<
sz
;
off
+=
sizeof
(
struct
dirent
))
{
if
(
read
(
fd
,
&
d
irent
,
sizeof
dirent
)
!=
sizeof
dirent
)
{
for
(
off
=
0
;
off
<
sz
;
off
+=
sizeof
(
de
))
{
if
(
read
(
fd
,
&
d
e
,
sizeof
(
de
)
)
!=
sizeof
(
de
)
)
{
printf
(
1
,
"ls: read error
\n
"
);
break
;
}
if
(
d
irent
.
inum
!=
0
)
{
if
(
d
e
.
inum
!=
0
)
{
p
=
buf
;
if
(
argc
==
2
)
{
strcpy
(
p
,
argv
[
1
]);
...
...
@@ -71,13 +68,14 @@ main(int argc, char *argv[])
if
(
*
(
p
-
1
)
!=
'/'
)
*
p
++
=
'/'
;
}
strcpy
(
p
,
dirent
.
name
);
memmove
(
p
,
de
.
name
,
DIRSIZ
);
p
[
DIRSIZ
]
=
0
;
if
(
stat
(
buf
,
&
st
)
<
0
)
{
printf
(
1
,
"stat: failed %s
\n
"
,
d
irent
.
name
);
printf
(
1
,
"stat: failed %s
\n
"
,
d
e
.
name
);
continue
;
}
pname
(
d
irent
.
name
);
printf
(
1
,
"%d %d %d
\n
"
,
st
.
type
,
d
irent
.
inum
,
st
.
size
);
pname
(
d
e
.
name
);
printf
(
1
,
"%d %d %d
\n
"
,
st
.
type
,
d
e
.
inum
,
st
.
size
);
}
}
break
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment