int main(int argc, char *argv[]) { int which, prio; id_t who; if (argc != 4 || strchr("pgu", argv[1][0]) == NULL) usageErr("%s {p|g|u} who priority\n" " set priority of: p=process; g=process group; " "u=processes for user\n", argv[0]); /* Set nice value according to command-line arguments */ which = (argv[1][0] == 'p') ? PRIO_PROCESS : (argv[1][0] == 'g') ? PRIO_PGRP : PRIO_USER; who = getLong(argv[2], 0, "who"); prio = getInt(argv[3], 0, "prio"); if (setpriority(which, who, prio) == -1) errExit("setpriority"); /* Retrieve nice value to check the change */ errno = 0; /* Because successful call may return -1 */ prio = getpriority(which, who); if (prio == -1 && errno != 0) errExit("getpriority"); printf("Nice value = %d\n", prio); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { size_t bufSize, numBytes, thisWrite, totWritten; char *buf; int fd, openFlags; if (argc != 4 || strcmp(argv[1], "--help") == 0) usageErr("%s file num-bytes buf-size\n", argv[0]); numBytes = getLong(argv[2], GN_GT_0, "num-bytes"); bufSize = getLong(argv[3], GN_GT_0, "buf-size"); buf = malloc(bufSize); if (buf == NULL) errExit("malloc"); openFlags = O_CREAT | O_WRONLY; #if defined(USE_O_SYNC) && defined(O_SYNC) openFlags |= O_SYNC; #endif fd = open(argv[1], openFlags, S_IRUSR | S_IWUSR); if (fd == -1) errExit("open"); for (totWritten = 0; totWritten < numBytes; totWritten += thisWrite) { thisWrite = min(bufSize, numBytes - totWritten); if (write(fd, buf, thisWrite) != thisWrite) fatal("partial/failed write"); #ifdef USE_FSYNC if (fsync(fd)) errExit("fsync"); #endif #ifdef USE_FDATASYNC if (fdatasync(fd)) errExit("fdatasync"); #endif } if (close(fd) == -1) errExit("close"); exit(EXIT_SUCCESS); }
//********************************************************************** // void CLatLongDistanceLayer::build() // build //********************************************************************** void CLatLongDistanceLayer::build() { try { // Get our Layers and validate values pLatLayer = CLayerManager::Instance()->getNumericLayer(sLatLayer); pLongLayer = CLayerManager::Instance()->getNumericLayer(sLongLayer); for (int i = 0; i < iHeight; ++i) { for (int j = 0; j < iWidth; ++j) { double dLong = getLong(i, j); double dLat = getLat(i, j); if (dLat < -90) CError::errorLessThan(PARAM_LAT_LAYER,"-90"); if (dLat > 90) CError::errorGreaterThan(PARAM_LAT_LAYER,"90"); if (dLong < 0) CError::errorLessThan(PARAM_LONG_LAYER,"0"); if (dLong > 360) CError::errorGreaterThan(PARAM_LONG_LAYER,"360"); } } rebuild(); } catch (string &Ex) { Ex = "CLatLongDistanceLayer.build(" + getLabel() + ")->" + Ex; throw Ex; } }
/** * \ingroup tcpcmdhelper * IP aus CMD-Parameter im EEPROM speichern * * \param[in] eeprom_adresse Speicheradresse im EEPROM */ void write_eeprom_ip (unsigned int eeprom_adresse) { uint32_t var; if (getLong(&var)) { //value ins EEPROM schreiben for (unsigned char count = 0; count<4;count++) { eeprom_busy_wait (); eeprom_write_byte((unsigned char *)(eeprom_adresse + count),(uint8_t)var); if (!getLong(&var)) break; } } }
long long SBQLConfig::getLongDefault(const string ¶m, long long def) const { long long res; if (!getLong(param, res)) return res; else return def; }
int main(void) { char c = '\0'; int i = 0; long l = 0L; float f = 0.0F; double d = 0.0F; char * s = NULL; printf("Enter char: "); c = getChar(); printf("Entered: %c\n", c); printf("Enter int: "); i = getInt(); printf("Entered: %d\n", i); printf("Enter long: "); l = getLong(); printf("Entered: %ld\n", l); printf("Enter float: "); f = getFloat(); printf("Entered: %f\n", f); printf("Enter double: "); d = getDouble(); printf("Entered: %f\n", d); printf("Enter string: "); s = getNewString(); printf("Entered: %s\n", s); free(s); return 0; }
ventas_horarias* getVentasHorarias(int* cantidades_ventas) { ventas_horarias* ventas = NULL; int i = 0; int num = 0; PGconn *conexion = NULL; PGresult *resultado = NULL; conexion = dbconnect(SERVIDOR, PUERTO, NOMBREDB, USUARIODB, PASSDB); if (conexion != NULL) { resultado = dbquery(conexion, "SELECT DISTINCT ON (tienda) tienda, EXTRACT(hour FROM fecha) AS hora,SUM(monto) AS total FROM ventas GROUP BY tienda, hora ORDER BY tienda, SUM(monto) DESC"); num = dbnumrows(resultado); if (num > 0) { ventas = (ventas_horarias *) malloc(num * sizeof (ventas_horarias)); for (i = 0; i < num; i++) { ventas[i].tienda = getString(dbresult(resultado, i, 0)); ventas[i].hora = getInt(dbresult(resultado, i, 1)); ventas[i].monto = getLong(dbresult(resultado, i, 2)); } dbfree(resultado); } dbclose(conexion); } *cantidades_ventas = num; return ventas; }
Variant FirebirdColumn::getValue() { if (isNull()) return Variant(); switch (_var->sqltype & ~1) { case SQL_TEXT: case SQL_VARYING: return getString(); case SQL_SHORT: case SQL_LONG: if (_var->sqlscale == 0) return int64_t(getLong()); return getDouble(); case SQL_INT64: if (_var->sqlscale == 0) return Variant(int64_t(getDouble())); return getDouble(); case SQL_FLOAT: case SQL_DOUBLE: return getDouble(); case SQL_TYPE_DATE: return getDate(); case SQL_TYPE_TIME: return getTime(); default: break; } qWarning("Sqlda::getValue: invalid type: %d", _var->sqltype); return Variant(); }
ranking_profesor *ranking_docentes(int semestre, int anio, long *tamano) { ranking_profesor *ranking = NULL; char sql[512]; int i = 0; int num = 0; PGconn *conexion = NULL; PGresult *resultado = NULL; if (semestre > 0 && anio > 0) { memset(sql, 0, sizeof (sql)); sprintf(sql, "SELECT cursos.docente_id, AVG(asignaturas_cursadas.nota) AS promedio, STDDEV(asignaturas_cursadas.nota) FROM cursos INNER JOIN asignaturas_cursadas ON cursos.curso_id=asignaturas_cursadas.curso_id WHERE cursos.semestre='%d' AND cursos.anio='%d' GROUP BY cursos.docente_id ORDER BY promedio DESC", semestre, anio); conexion = dbconnect(SERVIDOR, PUERTO, NOMBREDB, USUARIODB, PASSDB); if (conexion != NULL) { resultado = dbquery(conexion, sql); num = dbnumrows(resultado); if (num > 0) { ranking = (ranking_profesor *) malloc(num * sizeof (ranking_profesor)); for (i = 0; i < num; i++) { ranking[i].lugar = i + 1; ranking[i].docente_id = getLong(dbresult(resultado, i, 0)); ranking[i].nota = getDouble(dbresult(resultado, i, 1)); ranking[i].stddev = getDouble(dbresult(resultado, i, 2)); ranking[i].semestre = semestre; ranking[i].anio = anio; } dbfree(resultado); } dbclose(conexion); } } *tamano = num; return ranking; }
int main(int argc, char *argv[]) { int sig, numSigs, j, sigData; union sigval sv; if (argc < 4 || strcmp(argv[1], "--help") == 0) usageErr("%s pid sig-num data [num-sigs]\n", argv[0]); /* Display our PID and UID, so that they can be compared with the corresponding fields of the siginfo_t argument supplied to the handler in the receiving process */ printf("%s: PID is %ld, UID is %ld\n", argv[0], (long) getpid(), (long) getuid()); sig = getInt(argv[2], 0, "sig-num"); sigData = getInt(argv[3], GN_ANY_BASE, "data"); numSigs = (argc > 4) ? getInt(argv[4], GN_GT_0, "num-sigs") : 1; for (j = 0; j < numSigs; j++) { sv.sival_int = sigData + j; if (sigqueue(getLong(argv[1], 0, "pid"), sig, sv) == -1) errExit("sigqueue %d", j); } exit(EXIT_SUCCESS); }
int MAX::renew() { BufIn(GPSBuf); int i = getPhrase(GPSBuf, GPSPhr); if(i == 1) return 0; //not renewed else{ String tempLat = getLat(GPSPhr); String tempLng = getLong(GPSPhr); String temphgt = getHigh(GPSPhr); int a = spellCheck(tempLat); int b = spellCheck(tempLng); int c = spellCheck(temphgt); if(a == 0) {sLatitude = tempLat;} if(b == 0) sLongitude = tempLng; if(c == 0) sHeight = temphgt; int r = StoF(); if(r==0){ count ++; return 1; } else if(r==-1) {return 0;} } }
jint Java_org_videolan_libvlc_MediaList_expandMedia(JNIEnv *env, jobject thiz, jobject libvlcJava, jint position, jobject children) { return (jint)expand_media_internal(env, (libvlc_instance_t*)(intptr_t)getLong(env, libvlcJava, "mLibVlcInstance"), children, (libvlc_media_t*)libvlc_media_player_get_media((libvlc_media_player_t*)(intptr_t)getLong(env, libvlcJava, "mInternalMediaPlayerInstance")) ); }
int main(int argc, char *argv[]) { pid_t pid; cpu_set_t set; int cpu; unsigned long mask; if (argc != 3 || strcmp(argv[1], "--help") == 0) usageErr("%s pid mask\n", argv[0]); pid = getInt(argv[1], GN_NONNEG, "pid"); mask = getLong(argv[2], GN_ANY_BASE, "octal-mask"); CPU_ZERO(&set); for (cpu = 0; mask > 0; cpu++, mask >>= 1) if (mask & 1) CPU_SET(cpu, &set); if (sched_setaffinity(pid, sizeof(set), &set) == -1) errExit("sched_setaffinity"); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { int s, sig; if (argc != 3 || strcmp(argv[1], "--help") == 0) usageErr("%s pid sig-num\n", argv[0]); sig = getInt(argv[2], 0, "sig-num"); s = kill(getLong(argv[1], 0, "pid"), sig); if (sig != 0) { if (s == -1) errExit("kill"); } else { if (s == 0) { printf("Process exists and we can send it a signal\n"); } else { if (errno == EPERM) printf("Process exists, but we don't have " "permission to send it a signal\n"); else if (errno == ESRCH) printf("Process does not exist\n"); else errExit("kill"); } } exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { int numSigs, sig, j; pid_t pid; if (argc < 4 || strcmp(argv[1], "--help") == 0) usageErr("%s pid num-sigs sig-num [sig-num-2]\n", argv[0]); pid = getLong(argv[1], 0, "PID"); numSigs = getInt(argv[2], GN_GT_0, "num-sigs"); sig = getInt(argv[3], 0, "sig-num"); /* Send signals to receiver */ printf("%s: sending signal %d to process %ld %d times\n", argv[0], sig, (long) pid, numSigs); for (j = 0; j < numSigs; j++) if (kill(pid, sig) == -1) errExit("kill"); /* If a fourth command-line argument was specified, send that signal */ if (argc > 4) if (kill(pid, getInt(argv[4], 0, "sig-num-2")) == -1) errExit("kill"); printf("%s: exiting\n", argv[0]); exit(EXIT_SUCCESS); }
int LinearAffineEq::buildLookupTableAndCheck(mat_GF2 & Ta, bsetElem cst, smap & mapA){ for(unsigned int i=0; i<size; i++){ mat_GF2 e = colVector(i); mat_GF2 v = Ta * e; GF2X res = colVector_GF2X(v, 0); bsetElem resE = getLong(res) + cst; // check mapping, if it is correct (consistent table data with new computed data) if (mapA.count(i)>0){ if (mapA[i] != resE) { if (verbosity){ cout << "Mapping inconsistent for i=" << i << "; mapA[i] = " << mapA[i] << "; resE = " << resE << endl; cout << "colVector: " << endl; dumpMatrix(e); cout << " Ta*e " << endl; dumpMatrix(v); cout << "res: " << res << endl; } return -4; } } else { mapA.insert(smapElem(i, resE)); } } return 0; }
ventas_mensuales* getVentasMensuales(char* tienda, int* cantidades_ventas) { ventas_mensuales* ventas = NULL; int i = 0; int num = 0; PGconn *conexion = NULL; PGresult *resultado = NULL; char sql[513]; if (tienda != NULL) { conexion = dbconnect(SERVIDOR, PUERTO, NOMBREDB, USUARIODB, PASSDB); if (conexion != NULL) { memset(sql, 0, sizeof (sql)); snprintf(sql, 512, "SELECT tienda, EXTRACT(month FROM fecha) AS mes,SUM(monto) AS total FROM ventas WHERE tienda = '%s' GROUP BY tienda, mes ORDER BY mes", tienda); resultado = dbquery(conexion, sql); num = dbnumrows(resultado); if (num > 0) { ventas = (ventas_mensuales *) malloc(num * sizeof (ventas_mensuales)); for (i = 0; i < num; i++) { ventas[i].tienda = getString(dbresult(resultado, i, 0)); ventas[i].mes = getInt(dbresult(resultado, i, 1)); ventas[i].monto = getLong(dbresult(resultado, i, 2)); } dbfree(resultado); } dbclose(conexion); } } *cantidades_ventas = num; return ventas; }
ventas_anuales* getVentasAnuales(int* cantidades_ventas) { ventas_anuales* ventas = NULL; int i = 0; int num = 0; PGconn *conexion = NULL; PGresult *resultado = NULL; conexion = dbconnect(SERVIDOR, PUERTO, NOMBREDB, USUARIODB, PASSDB); if (conexion != NULL) { resultado = dbquery(conexion, "SELECT tienda, SUM(monto) FROM ventas GROUP BY tienda"); num = dbnumrows(resultado); if (num > 0) { ventas = (ventas_anuales *) malloc(num * sizeof (ventas_anuales)); for (i = 0; i < num; i++) { ventas[i].tienda = getString(dbresult(resultado, i, 0)); ventas[i].monto = getLong(dbresult(resultado, i, 1)); } dbfree(resultado); } dbclose(conexion); } *cantidades_ventas = num; return ventas; }
int TdApi::reqQryOrderInfo(dict req) { DFITCOrderField myreq = DFITCOrderField(); memset(&myreq, 0, sizeof(myreq)); getString(req, "instrumentID", myreq.instrumentID); getLong(req, "localOrderID", &myreq.localOrderID); getInt(req, "orderType", &myreq.orderType); getLong(req, "lRequestID", &myreq.lRequestID); getShort(req, "orderStatus", &myreq.orderStatus); getString(req, "customCategory", myreq.customCategory); getLong(req, "spdOrderID", &myreq.spdOrderID); getInt(req, "instrumentType", &myreq.instrumentType); getString(req, "accountID", myreq.accountID); int i = this->api->ReqQryOrderInfo(&myreq); return i; };
void BmpImage::readMetadata() { #ifdef DEBUG std::cerr << "Exiv2::BmpImage::readMetadata: Reading Windows bitmap file " << io_->path() << "\n"; #endif if (io_->open() != 0) { throw Error(9, io_->path(), strError()); } IoCloser closer(*io_); // Ensure that this is the correct image type if (!isBmpType(*io_, false)) { if (io_->error() || io_->eof()) throw Error(14); throw Error(3, "BMP"); } clearMetadata(); /* The Windows bitmap header goes as follows -- all numbers are in little-endian byte order: offset length name description ====== ======= ===================== ======= 0 2 bytes signature always 'BM' 2 4 bytes bitmap size 6 4 bytes reserved 10 4 bytes bitmap offset 14 4 bytes header size 18 4 bytes bitmap width 22 4 bytes bitmap height 26 2 bytes plane count 28 2 bytes depth 30 4 bytes compression 0 = none; 1 = RLE, 8 bits/pixel; 2 = RLE, 4 bits/pixel; 3 = bitfield; 4 = JPEG; 5 = PNG 34 4 bytes image size size of the raw bitmap data, in bytes 38 4 bytes horizontal resolution (in pixels per meter) 42 4 bytes vertical resolution (in pixels per meter) 46 4 bytes color count 50 4 bytes important colors number of "important" colors */ byte buf[54]; if (io_->read(buf, sizeof(buf)) == sizeof(buf)) { pixelWidth_ = getLong(buf + 18, littleEndian); pixelHeight_ = getLong(buf + 22, littleEndian); } } // BmpImage::readMetadata
int main(int argc, char *argv[]) { int flags, opt, fd; mode_t perms; size_t size; void *addr; flags = O_RDWR; while ((opt = getopt(argc, argv, "cx")) != -1) { switch (opt) { case 'c': flags |= O_CREAT; break; case 'x': flags |= O_EXCL; break; default: usageError(argv[0]); } } if (optind + 1 >= argc) usageError(argv[0]); size = getLong(argv[optind + 1], GN_ANY_BASE, "size"); perms = (argc <= optind + 2) ? (S_IRUSR | S_IWUSR) : getLong(argv[optind + 2], GN_BASE_8, "octal-perms"); /* Create shared memory object and set its size */ fd = shm_open(argv[optind], flags, perms); if (fd == -1) errExit("shm_open"); if (ftruncate(fd, size) == -1) errExit("ftruncate"); /* Map shared memory object */ addr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) errExit("mmap"); exit(EXIT_SUCCESS); }
const Reader &BasicReader::readLong (long& val ) { Glib::ustring buf = readWord(); long ival; if (getLong(buf, &ival)) val = ival; return *this; }
const Reader &BasicReader::readShort (short& val ) { Glib::ustring buf = readWord(); long ival; if (getLong(buf, &ival)) val = (short) ival; return *this; }
int TdApi::reqTradingDay(dict req) { DFITCTradingDayField myreq = DFITCTradingDayField(); memset(&myreq, 0, sizeof(myreq)); getLong(req, "lRequestID", &myreq.lRequestID); int i = this->api->ReqTradingDay(&myreq); return i; };
long SQLiteQuery::getLong(const std::string &name) { int col = m_aCols[name]; if (col >= 0) return getLong(col); return 0; }
int main(int argc, char *argv[]) { int fd; ssize_t numRead; size_t length, alignment; off_t offset; char *buf; if (argc < 3 || strcmp(argv[1], "--help") == 0) usageErr("%s file length [offset [alignment]]\n", argv[0]); length = getLong(argv[2], GN_ANY_BASE, "length"); offset = (argc > 3) ? getLong(argv[3], GN_ANY_BASE, "offset") : 0; alignment = (argc > 4) ? getLong(argv[4], GN_ANY_BASE, "alignment") : 4096; fd = open(argv[1], O_RDONLY | O_DIRECT); if (fd == -1) errExit("open"); /* memalign() allocates a block of memory aligned on an address that is a multiple of its first argument. By specifying this argument as 2 * 'alignment' and then adding 'alignment' to the returned pointer, we ensure that 'buf' is aligned on a non-power-of-two multiple of 'alignment'. We do this to ensure that if, for example, we ask for a 256-byte aligned buffer, we don't accidentally get a buffer that is also aligned on a 512-byte boundary. */ // http://www.man7.org/linux/man-pages/man3/memalign.3.html buf = memalign(alignment * 2, length + alignment); if (buf == NULL) errExit("memalign"); buf += alignment; if (lseek(fd, offset, SEEK_SET) == -1) errExit("lseek"); numRead = read(fd, buf, length); if (numRead == -1) errExit("read"); printf("Read %ld bytes\n", (long) numRead); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { struct timeval start, finish; struct timespec request, remain; struct sigaction sa; int s; if (argc != 3 || strcmp(argv[1], "--help") == 0) usageErr("%s secs nanosecs\n", argv[0]); request.tv_sec = getLong(argv[1], 0, "secs"); request.tv_nsec = getLong(argv[2], 0, "nanosecs"); /* Allow SIGINT handler to interrupt nanosleep() */ sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = sigintHandler; if (sigaction(SIGINT, &sa, NULL) == -1) errExit("sigaction"); if (gettimeofday(&start, NULL) == -1) errExit("gettimeofday"); for (;;) { s = nanosleep(&request, &remain); if (s == -1 && errno != EINTR) errExit("nanosleep"); if (gettimeofday(&finish, NULL) == -1) errExit("gettimeofday"); printf("Slept for: %9.6f secs\n", finish.tv_sec - start.tv_sec + (finish.tv_usec - start.tv_usec) / 1000000.0); if (s == 0) break; /* nanosleep() completed */ printf("Remaining: %2ld.%09ld\n", (long) remain.tv_sec, remain.tv_nsec); request = remain; /* Next sleep is with remaining time */ } printf("Sleep complete\n"); exit(EXIT_SUCCESS); }
int TdApi::reqQryCustomerCapital(dict req) { DFITCCapitalField myreq = DFITCCapitalField(); memset(&myreq, 0, sizeof(myreq)); getLong(req, "lRequestID", &myreq.lRequestID); getString(req, "accountID", myreq.accountID); int i = this->api->ReqQryCustomerCapital(&myreq); return i; };
int TdApi::reqQryExchangeStatus(dict req) { DFITCQryExchangeStatusField myreq = DFITCQryExchangeStatusField(); memset(&myreq, 0, sizeof(myreq)); getLong(req, "lRequestID", &myreq.lRequestID); getString(req, "exchangeID", myreq.exchangeID); int i = this->api->ReqQryExchangeStatus(&myreq); return i; };
int TdApi::reqQryTradeCode(dict req) { DFITCQryTradeCodeField myreq = DFITCQryTradeCodeField(); memset(&myreq, 0, sizeof(myreq)); getLong(req, "lRequestID", &myreq.lRequestID); getString(req, "accountID", myreq.accountID); int i = this->api->ReqQryTradeCode(&myreq); return i; };