Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSEP551
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
766ba5cc
Commit
766ba5cc
authored
17 years ago
by
rsc
Browse files
Options
Downloads
Patches
Plain Diff
first ever correct use of strncpy
parent
aa6824ab
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
defs.h
+1
-0
1 addition, 0 deletions
defs.h
fs.c
+2
-22
2 additions, 22 deletions
fs.c
string.c
+14
-2
14 additions, 2 deletions
string.c
with
17 additions
and
24 deletions
defs.h
+
1
−
0
View file @
766ba5cc
...
@@ -127,6 +127,7 @@ void* memset(void*, int, uint);
...
@@ -127,6 +127,7 @@ void* memset(void*, int, uint);
char
*
safestrcpy
(
char
*
,
const
char
*
,
int
);
char
*
safestrcpy
(
char
*
,
const
char
*
,
int
);
int
strlen
(
const
char
*
);
int
strlen
(
const
char
*
);
int
strncmp
(
const
char
*
,
const
char
*
,
uint
);
int
strncmp
(
const
char
*
,
const
char
*
,
uint
);
char
*
strncpy
(
char
*
,
const
char
*
,
int
);
// syscall.c
// syscall.c
int
argint
(
int
,
int
*
);
int
argint
(
int
,
int
*
);
...
...
This diff is collapsed.
Click to expand it.
fs.c
+
2
−
22
View file @
766ba5cc
...
@@ -455,15 +455,7 @@ writei(struct inode *ip, char *src, uint off, uint n)
...
@@ -455,15 +455,7 @@ writei(struct inode *ip, char *src, uint off, uint n)
int
int
namecmp
(
const
char
*
s
,
const
char
*
t
)
namecmp
(
const
char
*
s
,
const
char
*
t
)
{
{
int
i
;
return
strncmp
(
s
,
t
,
DIRSIZ
);
for
(
i
=
0
;
i
<
DIRSIZ
;
i
++
){
if
(
s
[
i
]
!=
t
[
i
])
return
s
[
i
]
-
t
[
i
];
if
(
s
[
i
]
==
0
)
break
;
}
return
0
;
}
}
// Look for a directory entry in a directory.
// Look for a directory entry in a directory.
...
@@ -500,18 +492,6 @@ dirlookup(struct inode *dp, char *name, uint *poff)
...
@@ -500,18 +492,6 @@ dirlookup(struct inode *dp, char *name, uint *poff)
return
0
;
return
0
;
}
}
// Copy one name to another.
static
void
namecpy
(
char
*
s
,
const
char
*
t
)
{
int
i
;
for
(
i
=
0
;
i
<
DIRSIZ
&&
t
[
i
];
i
++
)
s
[
i
]
=
t
[
i
];
for
(;
i
<
DIRSIZ
;
i
++
)
s
[
i
]
=
0
;
}
// Write a new directory entry (name, ino) into the directory dp.
// Write a new directory entry (name, ino) into the directory dp.
int
int
dirlink
(
struct
inode
*
dp
,
char
*
name
,
uint
ino
)
dirlink
(
struct
inode
*
dp
,
char
*
name
,
uint
ino
)
...
@@ -534,7 +514,7 @@ dirlink(struct inode *dp, char *name, uint ino)
...
@@ -534,7 +514,7 @@ dirlink(struct inode *dp, char *name, uint ino)
break
;
break
;
}
}
name
cpy
(
de
.
name
,
name
);
strn
cpy
(
de
.
name
,
name
,
DIRSIZ
);
de
.
inum
=
ino
;
de
.
inum
=
ino
;
if
(
writei
(
dp
,
(
char
*
)
&
de
,
off
,
sizeof
(
de
))
!=
sizeof
(
de
))
if
(
writei
(
dp
,
(
char
*
)
&
de
,
off
,
sizeof
(
de
))
!=
sizeof
(
de
))
panic
(
"dirwrite"
);
panic
(
"dirwrite"
);
...
...
This diff is collapsed.
Click to expand it.
string.c
+
14
−
2
View file @
766ba5cc
...
@@ -56,8 +56,20 @@ strncmp(const char *p, const char *q, uint n)
...
@@ -56,8 +56,20 @@ strncmp(const char *p, const char *q, uint n)
n
--
,
p
++
,
q
++
;
n
--
,
p
++
,
q
++
;
if
(
n
==
0
)
if
(
n
==
0
)
return
0
;
return
0
;
else
return
(
uchar
)
*
p
-
(
uchar
)
*
q
;
return
(
int
)
((
uchar
)
*
p
-
(
uchar
)
*
q
);
}
char
*
strncpy
(
char
*
s
,
const
char
*
t
,
int
n
)
{
char
*
os
;
os
=
s
;
while
(
n
--
>
0
&&
(
*
s
++
=
*
t
++
)
!=
0
)
;
while
(
n
--
>
0
)
*
s
++
=
0
;
return
os
;
}
}
// Like strncpy but guaranteed to NUL-terminate.
// Like strncpy but guaranteed to NUL-terminate.
...
...
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