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
408ec13e
Commit
408ec13e
authored
11 years ago
by
deuce
Browse files
Options
Downloads
Patches
Plain Diff
Add a POSIX.1 getdelim() implementation ispired by FreeBSDs.
parent
894bdb5b
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/xpdev/filewrap.c
+79
-0
79 additions, 0 deletions
src/xpdev/filewrap.c
src/xpdev/filewrap.h
+4
-0
4 additions, 0 deletions
src/xpdev/filewrap.h
src/xpdev/sockwrap.h
+1
-0
1 addition, 0 deletions
src/xpdev/sockwrap.h
with
84 additions
and
0 deletions
src/xpdev/filewrap.c
+
79
−
0
View file @
408ec13e
...
@@ -275,6 +275,85 @@ int DLLCALL unlock(int file, off_t offset, off_t size)
...
@@ -275,6 +275,85 @@ int DLLCALL unlock(int file, off_t offset, off_t size)
return
(
i
);
return
(
i
);
}
}
static
inline
size_t
p2roundup
(
size_t
n
)
{
if
(
n
&
(
n
-
1
))
{
// If n isn't a power of two already...
n
--
;
n
|=
n
>>
1
;
n
|=
n
>>
2
;
n
|=
n
>>
4
;
n
|=
n
>>
8
;
n
|=
n
>>
16
;
#if SIZE_T_MAX > 0xffffffffU
n
|=
n
>>
32
;
#endif
n
++
;
}
return
(
n
);
}
static
inline
int
expandtofit
(
char
**
linep
,
size_t
len
,
size_t
*
linecapp
)
{
char
*
newline
;
size_t
newcap
;
if
(
len
>
LONG_MAX
+
1
)
return
-
1
;
if
(
len
>
*
linecapp
)
{
if
(
len
==
LONG_MAX
+
1
)
newcap
=
LONG_MAX
+
1
;
else
newcap
=
p2roundup
(
len
);
newline
=
realloc
(
*
linep
,
newcap
);
if
(
newline
==
NULL
)
return
-
1
;
*
linecapp
=
newcap
;
*
linep
=
newline
;
}
return
0
;
}
long
getdelim
(
char
**
linep
,
size_t
*
linecapp
,
int
delimiter
,
FILE
*
stream
)
{
size_t
linelen
;
char
lbuf
[
1024
];
size_t
bc
;
char
*
term
=
NULL
;
long
pos
=
ftell
(
stream
);
if
(
linep
==
NULL
||
linecapp
==
NULL
)
return
-
1
;
if
(
*
linep
==
NULL
)
*
linecapp
=
0
;
if
(
feof
(
stream
))
{
if
(
expandtofit
(
linep
,
1
,
linecapp
))
return
-
1
;
(
*
linep
)[
0
]
=
0
;
return
-
1
;
}
linelen
=
0
;
for
(;;)
{
bc
=
fread
(
lbuf
,
1
,
sizeof
(
lbuf
),
stream
);
if
(
expandtofit
(
linep
,
linelen
+
bc
,
linecapp
))
return
-
1
;
memcpy
(
*
linep
+
linelen
,
lbuf
,
bc
);
term
=
strchr
(
*
linep
+
linelen
,
delimiter
);
linelen
+=
bc
;
if
(
bc
<
sizeof
(
lbuf
))
break
;
if
(
term
)
break
;
}
if
(
term
)
{
linelen
=
term
-
*
linep
;
linelen
++
;
fseek
(
stream
,
pos
+
linelen
,
SEEK_SET
);
}
return
linelen
;
}
#endif
/* !Unix && (MSVC || MinGW) */
#endif
/* !Unix && (MSVC || MinGW) */
#ifdef __unix__
#ifdef __unix__
...
...
This diff is collapsed.
Click to expand it.
src/xpdev/filewrap.h
+
4
−
0
View file @
408ec13e
...
@@ -166,6 +166,10 @@ extern "C" {
...
@@ -166,6 +166,10 @@ extern "C" {
DLLEXPORT
int
DLLCALL
unlock
(
int
fd
,
off_t
pos
,
off_t
len
);
DLLEXPORT
int
DLLCALL
unlock
(
int
fd
,
off_t
pos
,
off_t
len
);
#endif
#endif
#if (defined(_MSC_VER) || defined(__MINGW32__) || defined(__DMC__)) && !defined(__unix__)
long
getdelim
(
char
**
linep
,
size_t
*
linecapp
,
int
delimiter
,
FILE
*
stream
)
#endif
#if !defined(__BORLANDC__) && defined(__unix__)
#if !defined(__BORLANDC__) && defined(__unix__)
DLLEXPORT
int
DLLCALL
sopen
(
const
char
*
fn
,
int
sh_access
,
int
share
,
...);
DLLEXPORT
int
DLLCALL
sopen
(
const
char
*
fn
,
int
sh_access
,
int
share
,
...);
DLLEXPORT
off_t
DLLCALL
filelength
(
int
fd
);
DLLEXPORT
off_t
DLLCALL
filelength
(
int
fd
);
...
...
This diff is collapsed.
Click to expand it.
src/xpdev/sockwrap.h
+
1
−
0
View file @
408ec13e
...
@@ -48,6 +48,7 @@
...
@@ -48,6 +48,7 @@
#ifndef _WINSOCKAPI_
#ifndef _WINSOCKAPI_
#include
<winsock2.h>
/* socket/bind/etc. */
#include
<winsock2.h>
/* socket/bind/etc. */
#include
<mswsock.h>
/* Microsoft WinSock2 extensions */
#include
<mswsock.h>
/* Microsoft WinSock2 extensions */
#include
<wspiapi.h>
/* getaddrinfo() for Windows 2000 apparently */
#if defined(__BORLANDC__)
#if defined(__BORLANDC__)
// Borland C++ builder 6 comes with a broken ws2tcpip.h header for GCC.
// Borland C++ builder 6 comes with a broken ws2tcpip.h header for GCC.
#define _MSC_VER 7
#define _MSC_VER 7
...
...
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