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
7c1fb949
Commit
7c1fb949
authored
23 years ago
by
rswindell
Browse files
Options
Downloads
Patches
Plain Diff
Added lock, unlock, and readint methods.
parent
7632bab2
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
src/sbbs3/js_file.c
+78
-13
78 additions, 13 deletions
src/sbbs3/js_file.c
with
78 additions
and
13 deletions
src/sbbs3/js_file.c
+
78
−
13
View file @
7c1fb949
...
...
@@ -277,7 +277,6 @@ js_read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
char
buf
[
513
];
int
len
;
JSString
*
str
;
private_t
*
p
;
if
((
p
=
(
private_t
*
)
JS_GetPrivate
(
cx
,
obj
))
==
NULL
)
...
...
@@ -306,36 +305,104 @@ js_read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
}
static
JSBool
js_delete
(
JSContext
*
cx
,
JSObject
*
obj
,
uintN
argc
,
jsval
*
argv
,
jsval
*
rval
)
js_readln
(
JSContext
*
cx
,
JSObject
*
obj
,
uintN
argc
,
jsval
*
argv
,
jsval
*
rval
)
{
return
(
JS_TRUE
);
}
static
JSBool
js_readint
(
JSContext
*
cx
,
JSObject
*
obj
,
uintN
argc
,
jsval
*
argv
,
jsval
*
rval
)
{
BYTE
b
;
WORD
w
;
DWORD
l
;
size_t
size
=
sizeof
(
DWORD
);
private_t
*
p
;
*
rval
=
JSVAL_VOID
;
if
((
p
=
(
private_t
*
)
JS_GetPrivate
(
cx
,
obj
))
==
NULL
)
return
(
JS_FALSE
);
if
(
p
->
fp
!=
NULL
)
{
/* close it if it's open */
fclose
(
p
->
fp
);
p
->
fp
=
NULL
;
}
if
(
p
->
fp
==
NULL
)
return
(
JS_TRUE
);
*
rval
=
BOOLEAN_TO_JSVAL
(
remove
(
p
->
name
)
==
0
);
if
(
argc
>
1
)
size
=
JSVAL_TO_INT
(
argv
[
1
]);
switch
(
size
)
{
case
sizeof
(
BYTE
):
fread
(
&
b
,
1
,
size
,
p
->
fp
);
*
rval
=
INT_TO_JSVAL
(
b
);
break
;
case
sizeof
(
WORD
):
fread
(
&
w
,
1
,
size
,
p
->
fp
);
*
rval
=
INT_TO_JSVAL
(
w
);
break
;
case
sizeof
(
DWORD
):
fread
(
&
l
,
1
,
size
,
p
->
fp
);
*
rval
=
INT_TO_JSVAL
(
l
);
break
;
}
return
(
JS_TRUE
);
}
static
JSBool
js_
readln
(
JSContext
*
cx
,
JSObject
*
obj
,
uintN
argc
,
jsval
*
argv
,
jsval
*
rval
)
js_
lock
(
JSContext
*
cx
,
JSObject
*
obj
,
uintN
argc
,
jsval
*
argv
,
jsval
*
rval
)
{
private_t
*
p
;
*
rval
=
BOOLEAN_TO_JSVAL
(
JS_FALSE
);
if
((
p
=
(
private_t
*
)
JS_GetPrivate
(
cx
,
obj
))
==
NULL
)
return
(
JS_FALSE
);
if
(
p
->
fp
==
NULL
)
return
(
JS_TRUE
);
if
(
lock
(
fileno
(
p
->
fp
),
JSVAL_TO_INT
(
argv
[
0
]),
JSVAL_TO_INT
(
argv
[
1
]))
==
0
)
*
rval
=
BOOLEAN_TO_JSVAL
(
JS_TRUE
);
return
(
JS_TRUE
);
}
static
JSBool
js_
readint
(
JSContext
*
cx
,
JSObject
*
obj
,
uintN
argc
,
jsval
*
argv
,
jsval
*
rval
)
js_
unlock
(
JSContext
*
cx
,
JSObject
*
obj
,
uintN
argc
,
jsval
*
argv
,
jsval
*
rval
)
{
private_t
*
p
;
*
rval
=
BOOLEAN_TO_JSVAL
(
JS_FALSE
);
if
((
p
=
(
private_t
*
)
JS_GetPrivate
(
cx
,
obj
))
==
NULL
)
return
(
JS_FALSE
);
if
(
p
->
fp
==
NULL
)
return
(
JS_TRUE
);
if
(
unlock
(
fileno
(
p
->
fp
),
JSVAL_TO_INT
(
argv
[
0
]),
JSVAL_TO_INT
(
argv
[
1
]))
==
0
)
*
rval
=
BOOLEAN_TO_JSVAL
(
JS_TRUE
);
return
(
JS_TRUE
);
}
static
JSBool
js_delete
(
JSContext
*
cx
,
JSObject
*
obj
,
uintN
argc
,
jsval
*
argv
,
jsval
*
rval
)
{
private_t
*
p
;
if
((
p
=
(
private_t
*
)
JS_GetPrivate
(
cx
,
obj
))
==
NULL
)
return
(
JS_FALSE
);
if
(
p
->
fp
!=
NULL
)
{
/* close it if it's open */
fclose
(
p
->
fp
);
p
->
fp
=
NULL
;
}
*
rval
=
BOOLEAN_TO_JSVAL
(
remove
(
p
->
name
)
==
0
);
return
(
JS_TRUE
);
}
static
JSBool
js_flush
(
JSContext
*
cx
,
JSObject
*
obj
,
uintN
argc
,
jsval
*
argv
,
jsval
*
rval
)
...
...
@@ -522,10 +589,8 @@ static JSFunctionSpec js_file_functions[] = {
{
"remove"
,
js_delete
,
0
},
/* delete the file */
{
"clear_error"
,
js_clear_error
,
0
},
/* clear error */
{
"flush"
,
js_flush
,
0
},
/* flush buffers */
#if 0
{
"lock"
,
js_lock
,
2
},
/* lock offset, length */
{
"unlock"
,
js_unlock
,
2
},
/* unlock offset, length */
#endif
{
"read"
,
js_read
,
0
},
/* read a string */
{
"readln"
,
js_readln
,
0
},
/* read a \n terminated string */
{
"readint"
,
js_readint
,
0
},
/* read an integer (length) */
...
...
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