void ug_refresh(struct sysmon_envsys *sme, envsys_data_t *edata) { struct ug_softc *sc = sme->sme_cookie; /* Sensors return C while we need uK */ if (edata->sensor < UG_VOLT_MIN - 1) /* CPU and SYS Temps */ edata->value_cur = ug_read(sc, UG_CPUTEMP + edata->sensor) * 1000000 + 273150000; else if (edata->sensor == 2) /* PWMTEMP */ edata->value_cur = ug_read(sc, UG_PWMTEMP) * 1000000 + 273150000; /* Voltages */ #define VOLT_SENSOR UG_HTV + edata->sensor - UG_VOLT_MIN else if ((edata->sensor >= UG_VOLT_MIN) && (edata->sensor < UG_FAN_MIN)) { edata->value_cur = ug_read(sc, VOLT_SENSOR); switch(VOLT_SENSOR) { case UG_5V: /* 6V RFact */ case UG_5VSB: edata->value_cur *= UG_RFACT6; break; case UG_3V3: /* 4V RFact */ case UG_3VDUAL: edata->value_cur *= UG_RFACT4; break; default: /* 3V RFact */ edata->value_cur *= UG_RFACT3; break; } } else #undef VOLT_SENSOR /* and Fans */ if (edata->sensor >= UG_FAN_MIN) edata->value_cur = ug_read(sc, UG_CPUFAN + edata->sensor - UG_FAN_MIN) * UG_RFACT_FAN; }
static int decide_file_type (UgetPluginAria2* plugin) { char buf[11]; union { const char* ext; int fd; int path; } temp; plugin->uri_type = URI_UNSUPPORTED; // handle URI file:/// temp.path = plugin->uri_part.path; if (temp.path > 0 && plugin->uri_part.uri[temp.path] != 0) temp.path++; // temp.fd = ug_open (plugin->uri_part.uri + temp.path, UG_O_READONLY | UG_O_BINARY, UG_S_IREAD); if (temp.fd != -1 && ug_read (temp.fd, buf, 11) == 11) { if (strncmp (buf, "d8:announce", 11) == 0) plugin->uri_type = URI_TORRENT; else { buf[10] = 0; if (strchr (buf, '<')) plugin->uri_type = URI_METALINK; } } ug_close (temp.fd); if (plugin->uri_type == URI_UNSUPPORTED && ug_uri_part_file_ext (&plugin->uri_part, &temp.ext)) { if (temp.ext[0] == 'm' || temp.ext[0] == 'M') plugin->uri_type = URI_METALINK; else if (temp.ext[0] == 't' || temp.ext[0] == 'T') plugin->uri_type = URI_TORRENT; else plugin->uri_type = URI_UNSUPPORTED; } return plugin->uri_type; }
int ug_file_copy (const char *src_file_utf8, const char *new_file_utf8) { int src_fd; int new_fd; char* buf; int buf_len; int retval = 0; // new_fd = open (new_file_utf8, // O_BINARY | O_WRONLY | O_CREAT, // S_IREAD | S_IWRITE | S_IRGRP | S_IROTH); new_fd = ug_open (new_file_utf8, UG_O_BINARY | UG_O_WRONLY | UG_O_CREAT, UG_S_IREAD | UG_S_IWRITE | UG_S_IRGRP | UG_S_IROTH); if (new_fd == -1) return -1; // src_fd = open (src_file_utf8, O_BINARY | O_RDONLY, S_IREAD); src_fd = ug_open (src_file_utf8, UG_O_BINARY | UG_O_RDONLY, UG_S_IREAD); if (src_fd == -1) { ug_close (new_fd); return -1; } // read & write buf = ug_malloc (8192); for (;;) { buf_len = ug_read (src_fd, buf, 8192); if (buf_len <=0) break; if (ug_write (new_fd, buf, buf_len) != buf_len) { retval = -1; break; } } // clear ug_free (buf); ug_close (src_fd); ug_close (new_fd); return retval; }
static void* ug_file_to_base64 (const char* file, int* length) { int fd; int fsize, fpos = 0; int result_len; void* buffer; void* result; // fd = open (file, O_RDONLY | O_BINARY, S_IREAD); fd = ug_open (file, UG_O_READONLY | UG_O_BINARY, UG_S_IREAD); if (fd == -1) return NULL; // lseek (fd, 0, SEEK_END); ug_seek (fd, 0, SEEK_END); fsize = (int) ug_tell (fd); buffer = ug_malloc (fsize); // lseek (fd, 0, SEEK_SET); ug_seek (fd, 0, SEEK_SET); do { result_len = ug_read (fd, buffer, fsize - fpos); // result_len = read (fd, buffer, fsize - fpos); fpos += result_len; } while (result_len > 0); // close (fd); ug_close (fd); if (fsize != fpos) { ug_free (buffer); return NULL; } result = ug_base64_encode (buffer, fsize, &result_len); ug_free (buffer); if (length) *length = result_len; return result; }