Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sds
ssg
Commits
b684c98d
Commit
b684c98d
authored
Apr 08, 2016
by
Jonathan Jenkins
Browse files
add a file dump utility function
parent
33e78fd2
Pipeline
#19
skipped
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
include/ssg.h
View file @
b684c98d
...
...
@@ -66,6 +66,13 @@ const char * ssg_get_addr_str(const ssg_t s, int rank);
// group serialization mechanism
hg_return_t
hg_proc_ssg_t
(
hg_proc_t
proc
,
ssg_t
*
s
);
/// utility functions
// dump address list to the given file
// returns -1 on error, corresponding to the return code of open/write/close,
// and sets errno
int
ssg_dump
(
const
ssg_t
s
,
const
char
*
fname
);
#ifdef __cplusplus
}
#endif
...
...
src/ssg.c
View file @
b684c98d
...
...
@@ -2,6 +2,7 @@
#include
<sys/stat.h>
#include
<fcntl.h>
#include
<unistd.h>
#include
<errno.h>
#include
<stdlib.h>
#include
<string.h>
...
...
@@ -397,6 +398,47 @@ end:
return
hret
;
}
int
ssg_dump
(
const
ssg_t
s
,
const
char
*
fname
)
{
// file to write to
int
fd
=
-
1
;
ssize_t
written
;
// string to xform and dump
char
*
addrs_dup
=
NULL
;
char
*
tok
=
NULL
;
char
*
addrs_dup_end
=
NULL
;
// return code
int
ret
=
0
;
// copy the backing buffer, replacing the intermediate null chars with
// newlines (can't use strdup)
addrs_dup
=
malloc
(
s
->
buf_size
);
if
(
addrs_dup
==
NULL
)
{
errno
=
ENOMEM
;
ret
=
-
1
;
goto
end
;
}
memcpy
(
addrs_dup
,
s
->
backing_buf
,
s
->
buf_size
);
tok
=
addrs_dup
;
addrs_dup_end
=
addrs_dup
+
s
->
buf_size
;
for
(
int
i
=
0
;
i
<
s
->
num_addrs
-
1
;
i
++
)
{
tok
=
memchr
(
tok
,
'\0'
,
addrs_dup_end
-
tok
);
if
(
tok
==
NULL
)
{
errno
=
EINVAL
;
ret
=
-
1
;
goto
end
;
}
*
tok
=
'\n'
;
}
// open the file and dump in a single call
fd
=
open
(
fname
,
O_WRONLY
|
O_CREAT
|
O_EXCL
);
if
(
fd
==
-
1
)
{
ret
=
-
1
;
goto
end
;
}
// don't include the null char at the end
written
=
write
(
fd
,
addrs_dup
,
s
->
buf_size
-
1
);
if
(
written
!=
s
->
buf_size
-
1
)
ret
=
-
1
;
end:
free
(
addrs_dup
);
if
(
fd
!=
-
1
)
close
(
fd
);
return
ret
;
}
typedef
struct
serv_addr_out
{
hg_addr_t
addr
;
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment