forked from agorise/c-ipfs
Implemented conversion between PinMode and string.
This commit is contained in:
parent
ef380f2a69
commit
9d194ad484
2 changed files with 26 additions and 0 deletions
|
@ -29,4 +29,8 @@
|
|||
typedef int PinMode;
|
||||
|
||||
int ipfs_pin_init ();
|
||||
// Return pointer to string or NULL if invalid.
|
||||
char *ipfs_pin_mode_to_string (PinMode mode);
|
||||
// Return array index or -1 if fail.
|
||||
PinMode ipfs_string_to_pin_mode (char *str);
|
||||
#endif // IPFS_PIN_H
|
||||
|
|
22
pin/pin.c
22
pin/pin.c
|
@ -41,3 +41,25 @@ int ipfs_pin_init ()
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Return pointer to string or NULL if invalid.
|
||||
char *ipfs_pin_mode_to_string (PinMode mode)
|
||||
{
|
||||
if (mode < 0 || mode >= (sizeof (ipfs_pin_linkmap) / sizeof (void*))) {
|
||||
return NULL;
|
||||
}
|
||||
return (char*)ipfs_pin_linkmap[mode];
|
||||
}
|
||||
|
||||
// Return array index or -1 if fail.
|
||||
PinMode ipfs_string_to_pin_mode (char *str)
|
||||
{
|
||||
PinMode pm;
|
||||
|
||||
for (pm = 0 ; pm < (sizeof (ipfs_pin_linkmap) / sizeof (void*)) ; pm++) {
|
||||
if (strcmp(ipfs_pin_linkmap[pm], str) == 0) {
|
||||
return pm;
|
||||
}
|
||||
}
|
||||
return -1; // not found.
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue