Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TLMSP curl
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
CYBER - Cyber Security
TS 103 523 MSP
TLMSP
TLMSP curl
Commits
38ed72cd
Commit
38ed72cd
authored
12 years ago
by
Sebastian Rasmussen
Committed by
Daniel Stenberg
12 years ago
Browse files
Options
Downloads
Patches
Plain Diff
FILE: Make upload-writes unbuffered by not using FILE streams
parent
1099f3a0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/file.c
+18
-29
18 additions, 29 deletions
lib/file.c
with
18 additions
and
29 deletions
lib/file.c
+
18
−
29
View file @
38ed72cd
...
...
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 201
1
, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 201
2
, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
...
...
@@ -310,7 +310,8 @@ static CURLcode file_upload(struct connectdata *conn)
{
struct
FILEPROTO
*
file
=
conn
->
data
->
state
.
proto
.
file
;
const
char
*
dir
=
strchr
(
file
->
path
,
DIRSEP
);
FILE
*
fp
;
int
fd
;
int
mode
;
CURLcode
res
=
CURLE_OK
;
struct
SessionHandle
*
data
=
conn
->
data
;
char
*
buf
=
data
->
state
.
buffer
;
...
...
@@ -333,33 +334,21 @@ static CURLcode file_upload(struct connectdata *conn)
return
CURLE_FILE_COULDNT_READ_FILE
;
/* fix: better error code */
if
(
!
dir
[
1
])
return
CURLE_FILE_COULDNT_READ_FILE
;
/* fix: better error code */
if
(
data
->
state
.
resume_from
)
fp
=
fopen
(
file
->
path
,
"ab"
);
else
{
int
fd
;
return
CURLE_FILE_COULDNT_READ_FILE
;
/* fix: better error code */
#ifdef DOS_FILESYSTEM
fd
=
open
(
file
->
path
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
|
O_BINARY
,
conn
->
data
->
set
.
new_file_perms
);
#else
fd
=
open
(
file
->
path
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
conn
->
data
->
set
.
new_file_perms
);
#endif
if
(
fd
<
0
)
{
failf
(
data
,
"Can't open %s for writing"
,
file
->
path
);
return
CURLE_WRITE_ERROR
;
}
#ifdef HAVE_FDOPEN
fp
=
fdopen
(
fd
,
"wb"
);
#ifdef O_BINARY
#define MODE_DEFAULT O_WRONLY|O_CREAT|O_BINARY
#else
close
(
fd
);
fp
=
fopen
(
file
->
path
,
"wb"
);
#define MODE_DEFAULT O_WRONLY|O_CREAT
#endif
}
if
(
!
fp
)
{
if
(
data
->
state
.
resume_from
)
mode
=
MODE_DEFAULT
|
O_APPEND
;
else
mode
=
MODE_DEFAULT
|
O_TRUNC
;
fd
=
open
(
file
->
path
,
mode
,
conn
->
data
->
set
.
new_file_perms
);
if
(
fd
<
0
)
{
failf
(
data
,
"Can't open %s for writing"
,
file
->
path
);
return
CURLE_WRITE_ERROR
;
}
...
...
@@ -370,8 +359,8 @@ static CURLcode file_upload(struct connectdata *conn)
/* treat the negative resume offset value as the case of "-" */
if
(
data
->
state
.
resume_from
<
0
)
{
if
(
fstat
(
f
ileno
(
fp
)
,
&
file_stat
))
{
f
close
(
f
p
);
if
(
fstat
(
f
d
,
&
file_stat
))
{
close
(
f
d
);
failf
(
data
,
"Can't get the size of %s"
,
file
->
path
);
return
CURLE_WRITE_ERROR
;
}
...
...
@@ -407,7 +396,7 @@ static CURLcode file_upload(struct connectdata *conn)
buf2
=
buf
;
/* write the data to the target */
nwrite
=
f
write
(
buf2
,
1
,
nread
,
fp
);
nwrite
=
write
(
fd
,
buf2
,
nread
);
if
(
nwrite
!=
nread
)
{
res
=
CURLE_SEND_ERROR
;
break
;
...
...
@@ -425,7 +414,7 @@ static CURLcode file_upload(struct connectdata *conn)
if
(
!
res
&&
Curl_pgrsUpdate
(
conn
))
res
=
CURLE_ABORTED_BY_CALLBACK
;
f
close
(
f
p
);
close
(
f
d
);
return
res
;
}
...
...
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