Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
ab7d3c3c
Commit
ab7d3c3c
authored
Jul 21, 2013
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net_Gets: rewrite, deal with errors
parent
0dce21c6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
27 deletions
+28
-27
src/network/io.c
src/network/io.c
+28
-27
No files found.
src/network/io.c
View file @
ab7d3c3c
...
@@ -484,46 +484,47 @@ error:
...
@@ -484,46 +484,47 @@ error:
* This function is not thread-safe; the same file descriptor I/O cannot be
* This function is not thread-safe; the same file descriptor I/O cannot be
* read by another thread at the same time (although it can be written to).
* read by another thread at the same time (although it can be written to).
*
*
* @note This only works with stream-oriented file descriptors, not with
* datagram or packet-oriented ones.
*
* @return nul-terminated heap-allocated string, or NULL on I/O error.
* @return nul-terminated heap-allocated string, or NULL on I/O error.
*/
*/
char
*
net_Gets
(
vlc_object_t
*
p_this
,
int
fd
,
const
v_socket_t
*
p_vs
)
char
*
net_Gets
(
vlc_object_t
*
obj
,
int
fd
,
const
v_socket_t
*
vs
)
{
{
char
*
psz_line
=
NULL
,
*
ptr
=
NULL
;
char
*
buf
=
NULL
;
size_t
i_line
=
0
,
i_max
=
0
;
size_t
bufsize
=
0
,
buflen
=
0
;
for
(
;;
)
for
(;;
)
{
{
if
(
i_line
==
i_max
)
if
(
buflen
==
bufsize
)
{
{
i_max
+=
1024
;
if
(
unlikely
(
bufsize
>=
(
1
<<
10
)))
psz_line
=
xrealloc
(
psz_line
,
i_max
);
goto
error
;
/* put sane buffer size limit */
ptr
=
psz_line
+
i_line
;
}
if
(
net_Read
(
p_this
,
fd
,
p_vs
,
ptr
,
1
,
true
)
!=
1
)
char
*
newbuf
=
realloc
(
buf
,
bufsize
+
1024
);
{
if
(
unlikely
(
newbuf
==
NULL
))
if
(
i_line
==
0
)
goto
error
;
{
buf
=
newbuf
;
free
(
psz_line
);
bufsize
+=
1024
;
return
NULL
;
}
break
;
}
}
if
(
*
ptr
==
'\n'
)
ssize_t
val
=
net_Read
(
obj
,
fd
,
vs
,
buf
+
buflen
,
1
,
false
);
if
(
val
<
1
)
goto
error
;
if
(
buf
[
buflen
]
==
'\n'
)
break
;
break
;
i_line
++
;
buflen
++
;
ptr
++
;
}
}
*
ptr
--
=
'\0'
;
buf
[
--
buflen
]
=
'\0'
;
if
(
buflen
>
0
&&
buf
[
buflen
-
1
]
==
'\r'
)
if
(
(
ptr
>=
psz_line
)
&&
(
*
ptr
==
'\r'
)
)
buf
[
buflen
]
=
'\0'
;
*
ptr
=
'\0'
;
return
buf
;
error:
return
psz_line
;
free
(
buf
);
return
NULL
;
}
}
#undef net_Printf
#undef net_Printf
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment