Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
GHC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
alexbiehl-gc
GHC
Commits
5a2b8733
Commit
5a2b8733
authored
25 years ago
by
sof
Browse files
Options
Downloads
Patches
Plain Diff
[project @ 1999-09-19 19:25:24 by sof]
Allow seeking on devices and beyond EOF
parent
fe35817c
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
ghc/lib/std/cbits/seekFile.c
+13
-81
13 additions, 81 deletions
ghc/lib/std/cbits/seekFile.c
with
13 additions
and
81 deletions
ghc/lib/std/cbits/seekFile.c
+
13
−
81
View file @
5a2b8733
/*
* (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
*
* $Id: seekFile.c,v 1.
3
199
8/12/02
1
3
:2
7:53 simonm
Exp $
* $Id: seekFile.c,v 1.
4
199
9/09/19
1
9
:2
5:24 sof
Exp $
*
* hSeek and hIsSeekable Runtime Support
*/
...
...
@@ -32,10 +32,10 @@ StgByteArray d;
int
rc
=
0
;
switch
(
whence
)
{
case
0
:
whence
=
SEEK_SET
;
break
;
case
1
:
whence
=
SEEK_CUR
;
break
;
case
2
:
whence
=
SEEK_END
;
break
;
default:
whence
=
SEEK_SET
;
break
;
/* Should never happen, really */
case
0
:
whence
=
SEEK_SET
;
break
;
case
1
:
whence
=
SEEK_CUR
;
break
;
case
2
:
whence
=
SEEK_END
;
break
;
default:
whence
=
SEEK_SET
;
/* Should never happen, really */
}
/*
...
...
@@ -87,7 +87,7 @@ StgByteArray d;
rc
=
flushBuffer
(
ptr
);
if
(
rc
<
0
)
return
rc
;
/* Try to find out the file type
& size for a physical file
*/
/* Try to find out the file type */
while
(
fstat
(
fo
->
fd
,
&
sb
)
<
0
)
{
/* highly unlikely */
if
(
errno
!=
EINTR
)
{
...
...
@@ -96,44 +96,10 @@ StgByteArray d;
return
-
1
;
}
}
if
(
S_ISREG
(
sb
.
st_mode
))
{
/* Verify that we are not seeking beyond end-of-file */
off_t
posn
;
switch
(
whence
)
{
case
SEEK_SET
:
posn
=
offset
;
break
;
case
SEEK_CUR
:
while
((
posn
=
lseek
(
fo
->
fd
,
0
,
SEEK_CUR
))
==
-
1
)
{
/* the possibility seems awfully remote */
if
(
errno
!=
EINTR
)
{
cvtErrno
();
stdErrno
();
return
-
1
;
}
}
posn
-=
posn_delta
;
posn
+=
offset
;
offset
-=
posn_delta
;
/* adjust the offset to include the buffer delta */
break
;
case
SEEK_END
:
posn
=
(
off_t
)
sb
.
st_size
+
offset
;
break
;
}
if
(
posn
>
sb
.
st_size
)
{
ghc_errtype
=
ERR_INVALIDARGUMENT
;
ghc_errstr
=
"seek position beyond end of file"
;
return
-
1
;
}
}
else
if
(
S_ISFIFO
(
sb
.
st_mode
))
{
if
(
S_ISFIFO
(
sb
.
st_mode
))
{
ghc_errtype
=
ERR_UNSUPPORTEDOPERATION
;
ghc_errstr
=
"can't seek on a pipe"
;
return
-
1
;
}
else
{
ghc_errtype
=
ERR_UNSUPPORTEDOPERATION
;
ghc_errstr
=
"can't seek on a device"
;
return
-
1
;
}
while
(
lseek
(
fo
->
fd
,
offset
,
whence
)
==
-
1
)
{
if
(
errno
!=
EINTR
)
{
...
...
@@ -203,44 +169,10 @@ StgInt64 d;
return
-
1
;
}
}
if
(
S_ISREG
(
sb
.
st_mode
))
{
/* Verify that we are not seeking beyond end-of-file */
off_t
posn
;
switch
(
whence
)
{
case
SEEK_SET
:
posn
=
offset
;
break
;
case
SEEK_CUR
:
while
((
posn
=
lseek
(
fo
->
fd
,
0
,
SEEK_CUR
))
==
-
1
)
{
/* the possibility seems awfully remote */
if
(
errno
!=
EINTR
)
{
cvtErrno
();
stdErrno
();
return
-
1
;
}
}
posn
-=
posn_delta
;
posn
+=
offset
;
offset
-=
posn_delta
;
/* adjust the offset to include the buffer delta */
break
;
case
SEEK_END
:
posn
=
(
off_t
)
sb
.
st_size
+
offset
;
break
;
}
if
(
posn
>
sb
.
st_size
)
{
ghc_errtype
=
ERR_INVALIDARGUMENT
;
ghc_errstr
=
"seek position beyond end of file"
;
return
-
1
;
}
}
else
if
(
S_ISFIFO
(
sb
.
st_mode
))
{
if
(
S_ISFIFO
(
sb
.
st_mode
))
{
ghc_errtype
=
ERR_UNSUPPORTEDOPERATION
;
ghc_errstr
=
"can't seek on a pipe"
;
return
-
1
;
}
else
{
ghc_errtype
=
ERR_UNSUPPORTEDOPERATION
;
ghc_errstr
=
"can't seek on a device"
;
return
-
1
;
}
while
(
lseek
(
fo
->
fd
,
offset
,
whence
)
==
-
1
)
{
if
(
errno
!=
EINTR
)
{
...
...
@@ -270,12 +202,12 @@ StgForeignPtr ptr;
return
-
1
;
}
}
/*
Regular fil
es are okay */
if
(
S_IS
REG
(
sb
.
st_mode
))
{
return
1
;
/*
Pip
es are
not
okay
..
*/
if
(
S_IS
FIFO
(
sb
.
st_mode
))
{
return
0
;
}
/*
F
or now, everything else is
not
*/
/*
..f
or now, everything else is */
else
{
return
0
;
return
1
;
}
}
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