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
6cc93d8c
Commit
6cc93d8c
authored
5 months ago
by
Rob Swindell
Browse files
Options
Downloads
Patches
Plain Diff
Add a -l (loop) option to retry until failure
Pretty remedial option parsing here, the order is significant
parent
2e47ac98
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/xpdev/sopenfile.c
+39
-31
39 additions, 31 deletions
src/xpdev/sopenfile.c
with
39 additions
and
31 deletions
src/xpdev/sopenfile.c
+
39
−
31
View file @
6cc93d8c
...
...
@@ -7,11 +7,13 @@ int main(int argc, char** argv)
int
access
=
O_RDWR
;
char
*
share
=
"NWA"
;
bool
try_all
=
true
;
bool
loop
=
false
;
if
(
argc
<
2
)
{
printf
(
"usage: sopenfile [-r] <path/filename> [share-mode]
\n
"
);
printf
(
"usage: sopenfile [-r]
[-l]
<path/filename> [share-mode]
\n
"
);
printf
(
"
\n
"
);
printf
(
"-r open file read-only instead of read/write
\n
"
);
printf
(
"-l loop until failure
\n
"
);
printf
(
"
\n
"
);
printf
(
"share-mode: N (deny-none)
\n
"
);
printf
(
" W (deny-write)
\n
"
);
...
...
@@ -23,42 +25,48 @@ int main(int argc, char** argv)
access
=
O_RDONLY
;
++
argn
;
}
if
(
strcmp
(
argv
[
argn
],
"-l"
)
==
0
)
{
loop
=
true
;
++
argn
;
}
const
char
*
path
=
argv
[
argn
++
];
if
(
argc
>
argn
)
{
share
=
argv
[
argn
++
];
try_all
=
false
;
}
for
(
int
i
=
0
;
share
[
i
]
!=
'\0'
;
++
i
)
{
int
share_mode
=
0
;
char
share_flag
=
share
[
i
];
switch
(
toupper
(
share_flag
))
{
case
'N'
:
share_mode
=
SH_DENYNO
;
break
;
case
'W'
:
share_mode
=
SH_DENYWR
;
break
;
case
'A'
:
share_mode
=
SH_DENYRW
;
break
;
default:
fprintf
(
stderr
,
"Unrecognized share-mode: %c
\n
"
,
share_flag
);
return
EXIT_FAILURE
;
}
fprintf
(
stderr
,
"%s Deny-%c (share mode %x): "
,
path
,
toupper
(
share_flag
),
share_mode
);
int
file
=
sopen
(
path
,
access
,
share_mode
);
if
(
file
<
0
)
fprintf
(
stderr
,
"Error %d (%s)
\n
"
,
errno
,
strerror
(
errno
));
else
{
printf
(
"Success
\n
"
);
if
(
!
try_all
)
{
fprintf
(
stderr
,
"Hit enter
\n
"
);
getchar
();
do
{
for
(
int
i
=
0
;
share
[
i
]
!=
'\0'
;
++
i
)
{
int
share_mode
=
0
;
char
share_flag
=
share
[
i
];
switch
(
toupper
(
share_flag
))
{
case
'N'
:
share_mode
=
SH_DENYNO
;
break
;
case
'W'
:
share_mode
=
SH_DENYWR
;
break
;
case
'A'
:
share_mode
=
SH_DENYRW
;
break
;
default:
fprintf
(
stderr
,
"Unrecognized share-mode: %c
\n
"
,
share_flag
);
return
EXIT_FAILURE
;
}
fprintf
(
stderr
,
"%s Deny-%c (share mode %x): "
,
path
,
toupper
(
share_flag
),
share_mode
);
int
file
=
sopen
(
path
,
access
,
share_mode
);
if
(
file
<
0
)
fprintf
(
stderr
,
"Error %d (%s)
\n
"
,
errno
,
strerror
(
errno
));
else
{
printf
(
"Success
\n
"
);
if
(
!
try_all
)
{
fprintf
(
stderr
,
"Hit enter
\n
"
);
getchar
();
}
close
(
file
);
}
close
(
file
);
}
}
return
EXIT_SUCCESS
;
}
while
(
loop
&&
errno
==
0
);
return
errno
==
0
?
EXIT_SUCCESS
:
EXIT_FAILURE
;
}
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