Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
FMC DEL 1ns 4cha - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
FMC DEL 1ns 4cha - Software
Commits
e57731fa
Commit
e57731fa
authored
May 15, 2012
by
Alessandro Rubini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib and tools: fix sysfs_set (stdio ignores errors)
parent
f523e511
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
17 deletions
+31
-17
fdelay-lib.h
lib/fdelay-lib.h
+19
-9
fdelay-raw.h
tools/fdelay-raw.h
+12
-8
No files found.
lib/fdelay-lib.h
View file @
e57731fa
...
...
@@ -81,6 +81,10 @@ extern int fdelay_wr_mode(struct fdelay_board *b, int on);
extern
int
fdelay_check_wr_mode
(
struct
fdelay_board
*
b
);
#ifdef FDELAY_INTERNAL
/* Libray users should ignore what follows */
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
/* Internal structure */
struct
__fdelay_board
{
...
...
@@ -105,9 +109,11 @@ static inline int __fdelay_sysfs_get(char *path, uint32_t *resp)
if
(
!
f
)
return
-
1
;
errno
=
0
;
if
(
fscanf
(
f
,
"%i"
,
resp
)
!=
1
)
{
fclose
(
f
);
errno
=
EINVAL
;
if
(
!
errno
)
errno
=
EINVAL
;
return
-
1
;
}
fclose
(
f
);
...
...
@@ -116,17 +122,21 @@ static inline int __fdelay_sysfs_get(char *path, uint32_t *resp)
static
inline
int
__fdelay_sysfs_set
(
char
*
path
,
uint32_t
*
value
)
{
FILE
*
f
=
fopen
(
path
,
"w"
);
char
s
[
16
];
int
fd
,
ret
,
len
;
if
(
!
f
)
len
=
sprintf
(
s
,
"%i
\n
"
,
*
value
);
fd
=
open
(
path
,
O_WRONLY
);
if
(
fd
<
0
)
return
-
1
;
if
(
fprintf
(
f
,
"%i
\n
"
,
*
value
)
<
2
)
{
fclose
(
f
);
errno
=
EINVAL
;
ret
=
write
(
fd
,
s
,
len
);
close
(
fd
);
if
(
ret
<
0
)
return
-
1
;
}
fclose
(
f
);
return
0
;
if
(
ret
==
len
)
return
0
;
errno
=
EINVAL
;
return
-
1
;
}
/* And these two for the board structure */
...
...
tools/fdelay-raw.h
View file @
e57731fa
...
...
@@ -32,15 +32,19 @@ static inline int fdelay_sysfs_get(char *path, uint32_t *resp)
static
inline
int
fdelay_sysfs_set
(
char
*
path
,
uint32_t
*
value
)
{
FILE
*
f
=
fopen
(
path
,
"w"
);
char
s
[
16
];
int
fd
,
ret
,
len
;
if
(
!
f
)
len
=
sprintf
(
s
,
"%i
\n
"
,
*
value
);
fd
=
open
(
path
,
O_WRONLY
);
if
(
fd
<
0
)
return
-
1
;
if
(
fprintf
(
f
,
"%i
\n
"
,
*
value
)
<
2
)
{
fclose
(
f
);
errno
=
EINVAL
;
ret
=
write
(
fd
,
s
,
len
);
close
(
fd
);
if
(
ret
<
0
)
return
-
1
;
}
fclose
(
f
);
return
0
;
if
(
ret
==
len
)
return
0
;
errno
=
EINVAL
;
return
-
1
;
}
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