pndnotifyd: fix some crashes
[pandora-libraries.git] / include / pnd_utility.h
1
2 #ifndef h_pnd_utility_h
3 #define h_pnd_utility_h
4
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8
9 #include <time.h>
10
11 // expand_tilde() will only function correctly if a user is actually logged in; perhaps you
12 // want to spin until it looks like someone has in fact done so. (most devices will likely
13 // have auto-login, but its not instantaneous!)
14 //  r_username is optional; if present, will receive a copy of username
15 unsigned char pnd_check_login ( char *r_username, unsigned int maxlen );
16
17 // given a malloc'd pointer to a string, expand ~ to $HOME as often as it is found, returning a
18 // new string; the old string is destroyed in the process, or returned as-is.
19 char *pnd_expand_tilde ( char *freeable_buffer );
20
21 // arbtrary execute function; fire and forget really
22 void pnd_exec_no_wait_1 ( char *fullpath, char *arg1 );
23
24 //  NOTE: Does _NOT_ automatically pick up PXML-overrides; you can call that function if you want
25 pnd_pxml_handle *pnd_pxml_get_by_path ( char *fullpath );
26
27 // determine_mountpoint() will examine a path, and return the mountpoint that this path
28 // is sitting on; returns 1 on success, meaning the target was populated.
29 // consider for a similar effect: df /home -> look at "Mounted on"
30 unsigned char pnd_determine_mountpoint ( char *fullpath, char *r_mountpoint, unsigned int mountpoint_len );
31
32 // filecopy will return >0 on success
33 unsigned char pnd_filecopy ( char *sourcepath, char *targetpath );
34
35 // some lame file locking utility (not using 'flock')
36 // ** This is not race condition safe, so not for serious locking; this is just for casual locking, not high speed
37 #define PND_LOCK_PATH "/tmp" /* default path to stick lockfiles */
38 unsigned char pnd_lock ( char *lockname ); // return 0 on fail, >0 on success; lock file, not semaphore/etc
39 time_t pnd_is_locked ( char *lockname );   // return 0 on unlocked, >0 is epoch time when locked
40 void pnd_unlock ( char *lockname );        // assumes success
41 // wait 'max' occurances of microseconds (usleep) for unlock
42 // if max is 0, will not wait at all (will just check, same as pnd_is_locked())
43 // return '1' for unlock (may be immediate), 0 for failed 'max' timse
44 unsigned char pnd_wait_for_unlock ( char *lockname, unsigned short int max, unsigned int usec_delta );
45
46 #ifdef __cplusplus
47 } /* "C" */
48 #endif
49
50 #endif