~ubuntu-branches/ubuntu/saucy/libhdhomerun/saucy-proposed

« back to all changes in this revision

Viewing changes to hdhomerun_os_posix.c

  • Committer: Package Import Robot
  • Author(s): Francois Marier
  • Date: 2013-05-19 18:04:56 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130519180456-cqn35mqgbsrf7pxg
Tags: 20130328-1
* New upstream release
* Add CPPFLAGS to the upstream Makefile
* Bump Standards-Version up to 3.9.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
{
37
37
        FILE *fp = fopen("/dev/urandom", "rb");
38
38
        if (!fp) {
39
 
                return (uint32_t)rand();
 
39
                return (uint32_t)getcurrenttime();
40
40
        }
41
41
 
42
42
        uint32_t Result;
43
43
        if (fread(&Result, 4, 1, fp) != 1) {
44
 
                Result = (uint32_t)rand();
 
44
                Result = (uint32_t)getcurrenttime();
45
45
        }
46
46
 
47
47
        fclose(fp);
103
103
                msleep_approx(stop_time - current_time);
104
104
        }
105
105
}
 
106
 
 
107
bool_t hdhomerun_vsprintf(char *buffer, char *end, const char *fmt, va_list ap)
 
108
{
 
109
        if (buffer >= end) {
 
110
                return FALSE;
 
111
        }
 
112
 
 
113
        int length = vsnprintf(buffer, end - buffer - 1, fmt, ap);
 
114
        if (length < 0) {
 
115
                *buffer = 0;
 
116
                return FALSE;
 
117
        }
 
118
 
 
119
        if (buffer + length + 1 > end) {
 
120
                *(end - 1) = 0;
 
121
                return FALSE;
 
122
 
 
123
        }
 
124
 
 
125
        return TRUE;
 
126
}
 
127
 
 
128
bool_t hdhomerun_sprintf(char *buffer, char *end, const char *fmt, ...)
 
129
{
 
130
        va_list ap;
 
131
        va_start(ap, fmt);
 
132
        bool_t result = hdhomerun_vsprintf(buffer, end, fmt, ap);
 
133
        va_end(ap);
 
134
        return result;
 
135
}