Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
Main
Synchronet
Commits
aca246a6
Commit
aca246a6
authored
4 months ago
by
Rob Swindell
Browse files
Options
Downloads
Patches
Plain Diff
Add -2 (open second descriptor) and -t (second thread) options
Order of options no longer matters.
parent
c0528559
No related branches found
No related tags found
No related merge requests found
Pipeline
#7453
passed
4 months ago
Stage: build
Stage: test
Stage: cleanup
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/xpdev/sopenfile.c
+50
-18
50 additions, 18 deletions
src/xpdev/sopenfile.c
with
50 additions
and
18 deletions
src/xpdev/sopenfile.c
+
50
−
18
View file @
aca246a6
#include
"filewrap.h"
#include
"filewrap.h"
#include
"threadwrap.h"
#include
<stdlib.h>
#include
<stdlib.h>
#include
<string.h>
#include
<string.h>
int
access_
=
O_RDWR
;
void
child
(
void
*
arg
)
{
char
*
path
=
(
char
*
)
arg
;
printf
(
"Opening in child thread: "
);
int
fd
=
open
(
path
,
access_
,
DEFFILEMODE
);
if
(
fd
<
0
)
perror
(
path
);
else
{
printf
(
"Success
\n
"
);
printf
(
"close(%s) = %d
\n
"
,
path
,
close
(
fd
));
}
}
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
int
access
=
O_RDWR
;
char
*
share
=
"NWA"
;
char
*
share
=
"NWA"
;
bool
try_all
=
true
;
bool
try_all
=
true
;
bool
loop
=
false
;
bool
loop
=
false
;
bool
rm
=
false
;
bool
rm
=
false
;
bool
second
=
false
;
bool
thread
=
false
;
if
(
argc
<
2
)
{
if
(
argc
<
2
)
{
printf
(
"usage: sopenfile [-
r] [-l
] <path/filename> [share-mode]
\n
"
);
printf
(
"usage: sopenfile [-
opts
] <path/filename> [share-mode]
\n
"
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
printf
(
"-r open file read-only instead of read/write
\n
"
);
printf
(
"-r open file read-only instead of read/write
\n
"
);
printf
(
"-c open file with create permissions
\n
"
);
printf
(
"-c open file with create permissions
\n
"
);
printf
(
"-2 open and close a second descriptor
\n
"
);
printf
(
"-t open and close a second descriptor in a second thread
\n
"
);
printf
(
"-R remove file after open
\n
"
);
printf
(
"-R remove file after open
\n
"
);
printf
(
"-l loop until failure
\n
"
);
printf
(
"-l loop until failure
\n
"
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
...
@@ -24,21 +44,21 @@ int main(int argc, char** argv)
...
@@ -24,21 +44,21 @@ int main(int argc, char** argv)
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
int
argn
=
1
;
int
argn
=
1
;
if
(
strcmp
(
argv
[
argn
],
"-r"
)
==
0
)
{
for
(;
argn
<
argc
;
++
argn
)
{
access
=
O_RDONLY
;
if
(
strcmp
(
argv
[
argn
],
"-r"
)
==
0
)
++
argn
;
access_
=
O_RDONLY
;
}
else
if
(
strcmp
(
argv
[
argn
],
"-c"
)
==
0
)
if
(
strcmp
(
argv
[
argn
],
"-c"
)
==
0
)
{
access_
|=
O_CREAT
;
access
|=
O_CREAT
;
else
if
(
strcmp
(
argv
[
argn
],
"-2"
)
==
0
)
++
argv
;
second
=
true
;
}
else
if
(
strcmp
(
argv
[
argn
],
"-t"
)
==
0
)
if
(
strcmp
(
argv
[
argn
],
"-R"
)
==
0
)
{
thread
=
true
;
rm
=
true
;
else
if
(
strcmp
(
argv
[
argn
],
"-l"
)
==
0
)
++
argn
;
loop
=
true
;
}
else
if
(
strcmp
(
argv
[
argn
],
"-R"
)
==
0
)
if
(
strcmp
(
argv
[
argn
],
"-l"
)
==
0
)
{
rm
=
true
;
loop
=
true
;
else
++
argn
;
break
;
}
}
const
char
*
path
=
argv
[
argn
++
];
const
char
*
path
=
argv
[
argn
++
];
if
(
argc
>
argn
)
{
if
(
argc
>
argn
)
{
...
@@ -65,11 +85,23 @@ int main(int argc, char** argv)
...
@@ -65,11 +85,23 @@ int main(int argc, char** argv)
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
fprintf
(
stderr
,
"%s Deny-%c (share mode %x): "
,
path
,
toupper
(
share_flag
),
share_mode
);
fprintf
(
stderr
,
"%s Deny-%c (share mode %x): "
,
path
,
toupper
(
share_flag
),
share_mode
);
int
file
=
sopen
(
path
,
access
,
share_mode
,
DEFFILEMODE
);
int
file
=
sopen
(
path
,
access
_
,
share_mode
,
DEFFILEMODE
);
if
(
file
<
0
)
if
(
file
<
0
)
fprintf
(
stderr
,
"Error %d (%s)
\n
"
,
errno
,
strerror
(
errno
));
fprintf
(
stderr
,
"Error %d (%s)
\n
"
,
errno
,
strerror
(
errno
));
else
{
else
{
printf
(
"Success
\n
"
);
printf
(
"Success
\n
"
);
if
(
second
)
{
printf
(
"Opening second descriptor: "
);
int
fd2
=
open
(
path
,
access_
,
DEFFILEMODE
);
if
(
fd2
<
0
)
fprintf
(
stderr
,
"Error %d (%s)
\n
"
,
errno
,
strerror
(
errno
));
else
{
printf
(
"Success
\n
"
);
printf
(
"close(%s) = %d
\n
"
,
path
,
close
(
fd2
));
}
}
if
(
thread
)
_beginthread
(
child
,
0
,
(
void
*
)
path
);
if
(
rm
)
if
(
rm
)
printf
(
"remove(%s) = %d
\n
"
,
path
,
unlink
(
path
));
printf
(
"remove(%s) = %d
\n
"
,
path
,
unlink
(
path
));
if
(
!
try_all
)
{
if
(
!
try_all
)
{
...
...
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