int main() { char buf[BUFFER_SIZE]; int rc; printf("__GLIBC__ is %d and __GLIBC_MINOR__ is %d\n", __GLIBC__, __GLIBC_MINOR__); printf("gnu_get_libc_version() is %s\n", gnu_get_libc_version()); rc = confstr(_CS_GNU_LIBC_VERSION, buf, BUFFER_SIZE); if (rc < 0) { perror("confstr"); exit(EXIT_FAILURE); } printf("confstr(_CS_GNU_LIBC_VERSION, ...) returns %d with string %s\n", rc, buf); }
/** * Save a BSON obj representing the host system's details */ void ProcessInfo::SystemInfo::collectSystemInfo() { utsname unameData; string distroName, distroVersion; string cpuFreq, cpuFeatures; int cpuCount; string verSig = LinuxSysHelper::readLineFromFile( "/proc/version_signature" ); LinuxSysHelper::getCpuInfo(cpuCount, cpuFreq, cpuFeatures); LinuxSysHelper::getLinuxDistro( distroName, distroVersion ); if ( uname( &unameData ) == -1 ) { log() << "Unable to collect detailed system information: " << strerror( errno ) << endl; } osType = "Linux"; osName = distroName; osVersion = distroVersion; memSize = LinuxSysHelper::getSystemMemorySize(); addrSize = (string( unameData.machine ).find( "x86_64" ) != string::npos ? 64 : 32); numCores = cpuCount; pageSize = static_cast<unsigned long long>(sysconf( _SC_PAGESIZE )); cpuArch = unameData.machine; hasNuma = checkNumaEnabled(); BSONObjBuilder bExtra; bExtra.append( "versionString", LinuxSysHelper::readLineFromFile( "/proc/version" ) ); #ifdef __UCLIBC__ stringstream ss; ss << "uClibc-" << __UCLIBC_MAJOR__ << "." << __UCLIBC_MINOR__ << "." << __UCLIBC_SUBLEVEL__; bExtra.append( "libcVersion", ss.str() ); #else bExtra.append( "libcVersion", gnu_get_libc_version() ); #endif if (!verSig.empty()) // optional bExtra.append( "versionSignature", verSig ); bExtra.append( "kernelVersion", unameData.release ); bExtra.append( "cpuFrequencyMHz", cpuFreq); bExtra.append( "cpuFeatures", cpuFeatures); bExtra.append( "pageSize", static_cast<long long>(pageSize) ); bExtra.append( "numPages", static_cast< int >(sysconf( _SC_PHYS_PAGES ) ) ); bExtra.append( "maxOpenFiles", static_cast< int >(sysconf( _SC_OPEN_MAX ) ) ); _extraStats = bExtra.obj(); }
static int glibc_version_greater_than_2_2_4(void) /******************************************************************************* LAST MODIFIED : 25 January 2005 DESCRIPTION : Need to read the glibc version so that we can determine if we need to swap the endianness of values going into a64l ==============================================================================*/ { #if __GLIBC__ >= 2 char *version_string; int major_version, minor_version, minor_sub_version; #endif /* __GLIBC__ >= 2 */ static int return_code = -1; /* This gets called a lot so lets make it fast */ if (return_code == -1) { #if __GLIBC__ >= 2 version_string = (char *)gnu_get_libc_version(); if (sscanf(version_string, "%d.%d.%d", &major_version, &minor_version, &minor_sub_version)) { if ((major_version > 2) || ((major_version == 2) && (minor_version > 2)) || ((major_version == 2) && (minor_version == 2) && (minor_sub_version > 4))) { return_code = 1; } else { return_code = 0; } } else { return_code = 0; } #else /* __GLIBC__ >= 2 */ return_code = 0; #endif/* __GLIBC__ >= 2 */ } return (return_code); } /* get_glibc_version */
// private void ProcessInformation::SystemInformation::CollectSystemInformation () { int cpu_count; struct utsname uname_data; std::string distro_name; std::string distro_version; std::string cpu_frequncy; std::string cpu_features; std::string version_signature = detail::LinuxSystemHelper::ReadLineFromFile ("/proc/version_signature"); detail::LinuxSystemHelper::GetCpuInformation (cpu_count, cpu_frequncy, cpu_features); detail::LinuxSystemHelper::GetLinuxDistro (distro_name, distro_version); if (-1 == uname (&uname_data)) { LOG (ERROR) << "Unable to collect detailed system information: " << strerror (errno); } os_type_ = "Linux"; os_name_ = distro_name; os_version_ = distro_version; memory_size_ = detail::LinuxSystemHelper::GetSystemMemorySize (); address_size_ = (std::string (uname_data.machine).find ("x86_64") != std::string::npos ? 64 : 32); number_cores_ = cpu_count; page_size_ = static_cast<unsigned long long>(sysconf (_SC_PAGESIZE)); cpu_arch_ = uname_data.machine; has_numa_ = CheckNumaEnabled (); libc_version_ = gnu_get_libc_version (); version_signature_ = version_signature; kernel_version_ = uname_data.release; cpu_frequncy_ = cpu_frequncy; cpu_features_ = cpu_features; number_pages_ = static_cast<unsigned int>(sysconf (_SC_PHYS_PAGES)); max_open_files_ = static_cast<unsigned int>(sysconf (_SC_OPEN_MAX)); }
int main() { puts(gnu_get_libc_version()); }
int main(int argc, char *argv[]) { printf("GNU libc version: %s\n", gnu_get_libc_version()); exit(EXIT_SUCCESS); }
static void enable_thread_event_reporting (void) { td_thr_events_t events; td_err_e err; #ifdef HAVE_GNU_LIBC_VERSION_H const char *libc_version; int libc_major, libc_minor; #endif struct thread_db_info *info; info = get_thread_db_info (GET_PID (inferior_ptid)); /* We cannot use the thread event reporting facility if these functions aren't available. */ if (info->td_ta_event_addr_p == NULL || info->td_ta_set_event_p == NULL || info->td_ta_event_getmsg_p == NULL || info->td_thr_event_enable_p == NULL) return; /* Set the process wide mask saying which events we're interested in. */ td_event_emptyset (&events); td_event_addset (&events, TD_CREATE); #ifdef HAVE_GNU_LIBC_VERSION_H /* The event reporting facility is broken for TD_DEATH events in glibc 2.1.3, so don't enable it if we have glibc but a lower version. */ libc_version = gnu_get_libc_version (); if (sscanf (libc_version, "%d.%d", &libc_major, &libc_minor) == 2 && (libc_major > 2 || (libc_major == 2 && libc_minor > 1))) #endif td_event_addset (&events, TD_DEATH); err = info->td_ta_set_event_p (info->thread_agent, &events); if (err != TD_OK) { warning (_("Unable to set global thread event mask: %s"), thread_db_err_str (err)); return; } /* Delete previous thread event breakpoints, if any. */ remove_thread_event_breakpoints (); info->td_create_bp_addr = 0; info->td_death_bp_addr = 0; /* Set up the thread creation event. */ err = enable_thread_event (TD_CREATE, &info->td_create_bp_addr); if (err != TD_OK) { warning (_("Unable to get location for thread creation breakpoint: %s"), thread_db_err_str (err)); return; } /* Set up the thread death event. */ err = enable_thread_event (TD_DEATH, &info->td_death_bp_addr); if (err != TD_OK) { warning (_("Unable to get location for thread death breakpoint: %s"), thread_db_err_str (err)); return; } }
int main (void) { puts(gnu_get_libc_version()); return 0; }
static void glibc_version_check(void) { const char* version = gnu_get_libc_version(); platform_needs_custom_semaphore = version[0] == '2' && version[1] == '.' && atoi(version + 2) < 21; }
int main (void) { printf("%s\n", gnu_get_libc_version()); // or ldd --version return 0; }
int main() { char **k; printf("%s \n", gnu_get_libc_version()); return 0; }
/*{{{ main */ int main (int argc, char *argv[]) { Application *app; gboolean verbose = FALSE; gboolean version = FALSE; GError *error = NULL; GOptionContext *context; gchar **s_params = NULL; gchar **s_config = NULL; gboolean foreground = FALSE; gchar conf_str[1023]; struct stat st; gchar **cache_dir = NULL; gchar **s_fuse_opts = NULL; gchar **s_log_file = NULL; guint32 part_size = 0; gboolean disable_syslog = FALSE; gboolean disable_stats = FALSE; gboolean force_head_requests = FALSE; gint uid = -1; gint gid = -1; gint fmode = -1; gint dmode = -1; struct event_config *ev_config; srand (time (NULL)); app = g_new0 (Application, 1); app->conf_path = g_build_filename (SYSCONFDIR, "riofs.conf.xml", NULL); g_snprintf (conf_str, sizeof (conf_str), "Path to configuration file. Default: %s", app->conf_path); GOptionEntry entries[] = { { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &s_params, NULL, NULL }, { "config", 'c', 0, G_OPTION_ARG_FILENAME_ARRAY, &s_config, conf_str, NULL}, { "uid", 0, 0, G_OPTION_ARG_INT, &uid, "Set UID of filesystem owner.", NULL }, { "gid", 0, 0, G_OPTION_ARG_INT, &gid, "Set GID of filesystem owner.", NULL }, { "fmode", 0, 0, G_OPTION_ARG_INT, &fmode, "Set mode for all files.", NULL }, { "dmode", 0, 0, G_OPTION_ARG_INT, &dmode, "Set mode for all directories.", NULL }, { "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Flag. Do not daemonize process.", NULL }, { "cache-dir", 0, 0, G_OPTION_ARG_STRING_ARRAY, &cache_dir, "Set cache directory.", NULL }, { "fuse-options", 'o', 0, G_OPTION_ARG_STRING_ARRAY, &s_fuse_opts, "Fuse options.", "\"opt[,opt...]\"" }, { "disable-syslog", 0, 0, G_OPTION_ARG_NONE, &disable_syslog, "Flag. Disable logging to syslog.", NULL }, { "disable-stats", 0, 0, G_OPTION_ARG_NONE, &disable_stats, "Flag. Disable Statistics HTTP interface.", NULL }, { "part-size", 0, 0, G_OPTION_ARG_INT, &part_size, "Set file part size (in bytes).", NULL }, { "log-file", 'l', 0, G_OPTION_ARG_STRING_ARRAY, &s_log_file, "File to write output.", NULL }, { "force-head-requests", 0, 0, G_OPTION_ARG_NONE, &force_head_requests, "Flag. Send HEAD request for each file.", NULL }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose output.", NULL }, { "version", 'V', 0, G_OPTION_ARG_NONE, &version, "Show application version and exit.", NULL }, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } }; // init libraries CRYPTO_set_mem_functions (g_malloc0, g_realloc, g_free); ENGINE_load_builtin_engines (); ENGINE_register_all_complete (); ERR_load_crypto_strings (); OpenSSL_add_all_algorithms (); #ifdef SSL_ENABLED SSL_load_error_strings (); SSL_library_init (); #endif g_random_set_seed (time (NULL)); // init main app structure ev_config = event_config_new (); #if defined(__APPLE__) // method select is the preferred method on OS X. kqueue and poll are not supported. event_config_avoid_method (ev_config, "kqueue"); event_config_avoid_method (ev_config, "poll"); #endif app->evbase = event_base_new_with_config (ev_config); event_config_free (ev_config); if (!app->evbase) { LOG_err (APP_LOG, "Failed to create event base !"); application_destroy (app); return -1; } app->dns_base = evdns_base_new (app->evbase, 1); if (!app->dns_base) { LOG_err (APP_LOG, "Failed to create DNS base !"); application_destroy (app); return -1; } app->f_log = NULL; app->log_file_name = NULL; /*{{{ cmd line args */ // parse command line options context = g_option_context_new ("[bucketname] [mountpoint]"); g_option_context_add_main_entries (context, entries, NULL); g_option_context_set_description (context, "Please set both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables!"); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_fprintf (stderr, "Failed to parse command line options: %s\n", error->message); application_destroy (app); g_option_context_free (context); return -1; } g_option_context_free (context); // check if --version is specified if (version) { g_fprintf (stdout, "RioFS File System v%s\n", VERSION); g_fprintf (stdout, "Copyright (C) 2012-2014 Paul Ionkin <*****@*****.**>\n"); g_fprintf (stdout, "Copyright (C) 2012-2014 Skoobe GmbH. All rights reserved.\n"); g_fprintf (stdout, "Libraries:\n"); g_fprintf (stdout, " GLib: %d.%d.%d libevent: %s fuse: %d.%d", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION, LIBEVENT_VERSION, FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION ); #if defined(__APPLE__) || defined(__FreeBSD__) || !defined(__GLIBC__) g_fprintf (stdout, "\n"); #else g_fprintf (stdout, " glibc: %s\n", gnu_get_libc_version ()); #endif g_fprintf (stdout, "Features:\n"); g_fprintf (stdout, " libevent backend method: %s\n", event_base_get_method(app->evbase)); #ifdef SSL_ENABLED g_fprintf (stdout, " SSL enabled\n"); #endif /* { int i; const char **methods = event_get_supported_methods (); g_fprintf (stdout, " Available libevent backend methods:\n"); for (i = 0; methods[i] != NULL; ++i) { g_fprintf (stdout, " %s\n", methods[i]); } } */ return 0; } if (!s_params || g_strv_length (s_params) != 2) { LOG_err (APP_LOG, "Wrong number of provided arguments!\nTry `%s --help' for more information.", argv[0]); application_destroy (app); return -1; } if (verbose) log_level = LOG_debug; else log_level = LOG_msg; /*}}}*/ /*{{{ parse config file */ // user provided alternative config path if (s_config && g_strv_length (s_config) > 0) { g_free (app->conf_path); app->conf_path = g_strdup (s_config[0]); g_strfreev (s_config); } app->conf = conf_create (); if (access (app->conf_path, R_OK) == 0) { LOG_debug (APP_LOG, "Using config file: %s", app->conf_path); if (!conf_parse_file (app->conf, app->conf_path)) { LOG_err (APP_LOG, "Failed to parse configuration file: %s", app->conf_path); application_destroy (app); return -1; } } else { LOG_err (APP_LOG, "Configuration file is not found !"); application_destroy (app); return -1; } if (!conf_check_keys (app->conf, conf_keys_str, conf_keys_len)) { LOG_err (APP_LOG, "Configuration file is missing keys, please re-check your configuration file: %s", app->conf_path); application_destroy (app); return -1; } if (disable_syslog) { conf_set_boolean (app->conf, "log.use_syslog", FALSE); } // update logging settings logger_set_syslog (conf_get_boolean (app->conf, "log.use_syslog")); logger_set_color (conf_get_boolean (app->conf, "log.use_color")); if (cache_dir && g_strv_length (cache_dir) > 0) { conf_set_string (app->conf, "filesystem.cache_dir", cache_dir[0]); g_strfreev (cache_dir); } if (!verbose) log_level = conf_get_int (app->conf, "log.level"); if (uid >= 0) conf_set_int (app->conf, "filesystem.uid", uid); if (gid >= 0) conf_set_int (app->conf, "filesystem.gid", gid); if (fmode >= 0) conf_set_int (app->conf, "filesystem.file_mode", fmode); if (dmode >= 0) conf_set_int (app->conf, "filesystem.dir_mode", dmode); /*}}}*/ // try to get access parameters from the environment if (getenv ("AWS_ACCESS_KEY_ID")) { conf_set_string (app->conf, "s3.access_key_id", getenv ("AWS_ACCESS_KEY_ID")); // else check if it's set it the config file } else { if (!conf_node_exists (app->conf, "s3.access_key_id")) { LOG_err (APP_LOG, "Environment variables are not set!\nTry `%s --help' for more information.", argv[0]); application_destroy (app); return -1; } } if (getenv ("AWS_SECRET_ACCESS_KEY")) { conf_set_string (app->conf, "s3.secret_access_key", getenv ("AWS_SECRET_ACCESS_KEY")); } else { if (!conf_node_exists (app->conf, "s3.secret_access_key")) { LOG_err (APP_LOG, "Environment variables are not set!\nTry `%s --help' for more information.", argv[0]); application_destroy (app); return -1; } } // check if both strings are set if (!conf_get_string (app->conf, "s3.access_key_id") || !conf_get_string (app->conf, "s3.secret_access_key")) { LOG_err (APP_LOG, "Environment variables are not set!\nTry `%s --help' for more information.", argv[0]); application_destroy (app); return -1; } // foreground is set if (foreground) conf_set_boolean (app->conf, "app.foreground", foreground); if (part_size) conf_set_uint (app->conf, "s3.part_size", part_size); if (disable_stats) conf_set_boolean (app->conf, "statistics.enabled", FALSE); if (force_head_requests) conf_set_boolean (app->conf, "s3.force_head_requests_on_lookup", TRUE); else conf_set_boolean (app->conf, "s3.force_head_requests_on_lookup", FALSE); conf_set_string (app->conf, "s3.bucket_name", s_params[0]); if (!application_set_url (app, conf_get_string (app->conf, "s3.endpoint"))) { application_destroy (app); return -1; } if (s_fuse_opts && g_strv_length (s_fuse_opts) > 0) { app->fuse_opts = g_strdup (s_fuse_opts[0]); g_strfreev (s_fuse_opts); } if (s_log_file && g_strv_length (s_log_file) > 0) { app->log_file_name = g_strdup (s_log_file[0]); app->f_log = fopen (s_log_file[0], "a+"); if (!app->f_log) { LOG_err (APP_LOG, "Failed to open log file: %s Error: %s", s_log_file[0], strerror (errno)); application_destroy (app); return -1; } LOG_debug (APP_LOG, "Using %s for storing application logs.", s_log_file[0]); logger_set_file (app->f_log); g_strfreev (s_log_file); } conf_set_string (app->conf, "app.mountpoint", s_params[1]); // check if directory exists if (stat (conf_get_string (app->conf, "app.mountpoint"), &st) == -1) { LOG_err (APP_LOG, "Mountpoint %s does not exist! Please check directory permissions!", conf_get_string (app->conf, "app.mountpoint")); application_destroy (app); return -1; } // check if it's a directory if (!S_ISDIR (st.st_mode)) { LOG_err (APP_LOG, "Mountpoint %s is not a directory!", conf_get_string (app->conf, "app.mountpoint")); application_destroy (app); return -1; } g_strfreev (s_params); #ifdef SSL_ENABLED app->ssl_ctx = SSL_CTX_new (SSLv23_client_method ()); if (!app->ssl_ctx) { LOG_err (APP_LOG, "Failed to initialize SSL engine !"); application_exit (app); return -1; } SSL_CTX_set_options (app->ssl_ctx, SSL_OP_ALL); #endif #ifdef MAGIC_ENABLED app->magic_ctx = magic_open(MAGIC_MIME_TYPE); if (!app->magic_ctx) { LOG_err(APP_LOG, "Failed to initialize magic library\n"); return -1; } if (magic_load(app->magic_ctx, NULL)) { LOG_err(APP_LOG, "Failed to load magic database: %s\n", magic_error(app->magic_ctx)); magic_close(app->magic_ctx); return -1; } #endif app->stat_srv = stat_srv_create (app); if (!app->stat_srv) { application_exit (app); return -1; } // perform the initial request to get bucket ACL (handles redirect as well) app->service_con = http_connection_create (app); if (!app->service_con) { application_destroy (app); return -1; } bucket_client_get (app->service_con, "/?acl", application_on_bucket_acl_cb, app); // start the loop event_base_dispatch (app->evbase); application_destroy (app); return 0; }
int main(int argc, char *argv[]) { long i,j, status, myid; pid_t pid, pid_child_process, wait_pid_child_process; cpu_set_t new_mask,cur_mask; unsigned int len = sizeof(new_mask); pthread_t thread2; void *thread2_status; pthread_attr_t attr; if(argc <6) { printf("enter valid value as: loopIterationCount memLength{totalmemsize=memLength*([4*4*4]*3)} numThreadsToRun[1/2/4...16] doPROCBind(0 or 1) PROCFreqMHz RDTSCFreqMHz\nUsage:\n %s 1000 3 2 0 2600 6000 ;#loopIterationCount=1000, memLength=3 i.e. 3*[4*4*4]*3=576bytes numThreadsToRun=2 i.e. run with 2 Threads, doPROCBind=0 i.e. no CPU binding, PROCFreqMHz=2600 (PNR), RDTSCFreqMHz=2600 i.e. rdtsc clks is same as Proc Clks\n", argv[0]); exit(-1); } if (atoi(argv[1]) <= 0) { printf("using default value of loopIterationCount=%d\n", loopIterationCount); } else { loopIterationCount = atoi(argv[1]); } if (atoi(argv[2]) <= 1) { printf("using default value of mem Length=1\n"); InputData.Length=1; } else { InputData.Length = atoi(argv[2]); } //always if (atoi(argv[3]) <= 0) { printf("numThreadsToRun cannot be 0, using default value of %d\n", numThreadsToRun); } else { numThreadsToRun = atoi(argv[3]); } doPROCBind = atoi(argv[4]); if(doPROCBind < 0) { doPROCBind = 0; printf("doPROCBind cannot be < 0, using default value of %d\n", doPROCBind); } else if (doPROCBind > 1) { doPROCBind = 1; printf("doPROCBind cannot be > 1, using default value of %d\n", doPROCBind); } PROCFreqMHz = (uint64_t) atoi(argv[5]); RDTSCFreqMHz = (uint64_t) atoi(argv[6]); InputData.LoopIter = loopIterationCount; if (InputData.LoopIter == 0) InputData.LoopIter = 1; InputData.DelayCount=0; //always normFactor = (1.0 * PROCFreqMHz/RDTSCFreqMHz); printf("the LIBC version should be > 2.4 for this program, yours is "); puts(gnu_get_libc_version()); printf("### START CMDLINE PARAMS ###\n"); printf("\tfull_cmdline="); for(i=0; i<argc; i++) printf("%s ", argv[i]); printf("\n"); printf("\tloopIterationCount = %u\n", loopIterationCount); printf("\tInputData.Length=%u\n", InputData.Length); printf("\tnumThreadsToRun = %u\n", numThreadsToRun); printf("\tdoPROCBind = %d\n", doPROCBind); printf("\tPROCFreqMHz = %lld\n", PROCFreqMHz); printf("\tRDTSCFreqMHz = %lld\n", RDTSCFreqMHz); printf("other derived/constant params\n"); printf("\tnormFactor (PROCFreqMHz/RDTSCFreqMHz) = %-7.3f\n", normFactor); printf("\tInputData.DelayCount=%u\n", InputData.DelayCount); printf("### END ###\n\n"); numCPU=find_num_proc(); if(numCPU > MAX_CPU_SUPPORT) { printf("numCPU=%d > MAX_CPU_SUPPORT=%d, limiting to MAX_CPU_SUPPORT or change MAX_CPU_SUPPORT and re-compile\n", numCPU, MAX_CPU_SUPPORT); numCPU = MAX_CPU_SUPPORT; } if(numThreadsToRun > numCPU ) { printf("\n\n*** numThreadsToRun %d > numCPU %d, running only %d threads!!!\n\n", numThreadsToRun, numCPU, numCPU); numThreadsToRun=numCPU; } myid=0; //Main Thread's ID long tstatus; pthread_cond_init(&cond_thread1, NULL); pthread_mutex_init(&mutex_thread1, NULL); pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); for(i=1; i<numThreadsToRun; i++) { //i=0 is reserved for Main if ( (tstatus=pthread_create( &threads[i], &attr, worker_thread, (void *)i)) ) { printf("THREAD#%02d: error code %d when creating thread# %d\n", myid,tstatus, i); abort(); } } worker_thread((void*)myid); void *texitstatus; for(i=1; i<numThreadsToRun; i++) { //i=0 is reserved for Main if ( tstatus=pthread_join(threads[i], &texitstatus) ) { printf("THREAD#%02d: error code %d when creating thread# %d\n", myid, tstatus, i); abort(); } printf("THREAD#%02d: thread %d joined with status %d\n", myid, i, texitstatus); } pthread_attr_destroy(&attr); pthread_cond_destroy(&cond_thread1); pthread_mutex_destroy(&mutex_thread1); printResults(); exit(EXIT_SUCCESS); }
std::string getOSVersion() { #ifdef _WIN32 OSVERSIONINFOEX osvi; BOOL bOsVersionInfoEx; std::string bit=IsWow64()?" 64bit":" 32bit"; // Try calling GetVersionEx using the OSVERSIONINFOEX structure. // If that fails, try using the OSVERSIONINFO structure. ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) ) { osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) return "Unknown"; } switch (osvi.dwPlatformId) { // Test for the Windows NT product family. case VER_PLATFORM_WIN32_NT: // Test for the specific product. if ( osvi.dwMajorVersion == 10 && osvi.dwMinorVersion == 0 ) return "Microsoft Windows 10"+bit; if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 3 ) return "Microsoft Windows 8.1"+bit; if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 2 ) return "Microsoft Windows 8"+bit; if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1 ) return "Microsoft Windows 7"+bit; if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 ) return "Microsoft Windows Vista"+bit; if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ) return "Microsoft Windows Server 2003"+bit; if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) return "Microsoft Windows XP"+bit; if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) return "Microsoft Windows 2000"; if ( osvi.dwMajorVersion <= 4 ) return "Microsoft Windows NT"; // Test for the Windows Me/98/95. case VER_PLATFORM_WIN32_WINDOWS: if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0) { return "Microsoft Windows 95"; } if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) { return "Microsoft Windows 98"; } if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) { return "Microsoft Windows Millennium Edition"; } break; case VER_PLATFORM_WIN32s: return "Microsoft Win32s"; } return "Microsoft Windows"; #elif __linux utsname u; if ( uname(&u) != 0 ) { Logger::system().warning("Error detecting linux version"); return "Unknown"; } return std::string(u.sysname) + " " + u.release + " " + u.version + " " + u.machine + "; libc version: " + gnu_get_libc_version(); #else return "Unknown OS"; #endif }
int libc_cur_version (void) { int ret = strcmp (gnu_get_libc_version (), "2.2.2"); if (ret < 0) return OLD_LIBC_VERSION; return NEW_LIBC_VERSION; }
nsresult nsPlatformCharset::InitGetCharset(nsACString &oString) { char* nl_langinfo_codeset = nsnull; nsCString aCharset; nsresult res; #if HAVE_LANGINFO_CODESET nl_langinfo_codeset = nl_langinfo(CODESET); NS_ASSERTION(nl_langinfo_codeset, "cannot get nl_langinfo(CODESET)"); // // see if we can use nl_langinfo(CODESET) directly // if (nl_langinfo_codeset) { aCharset.Assign(nl_langinfo_codeset); res = VerifyCharset(aCharset); if (NS_SUCCEEDED(res)) { oString = aCharset; return res; } } // locked for thread safety { nsAutoLock guard(gLock); if (!gNLInfo) { nsCAutoString propertyFile; // note: NS_LITERAL_CSTRING("unixcharset." OSARCH ".properties") does not compile on AIX propertyFile.AssignLiteral("unixcharset."); propertyFile.AppendLiteral(NS_STRINGIFY(OSARCH)); propertyFile.AppendLiteral(".properties"); nsGREResProperties *info = new nsGREResProperties(propertyFile); NS_ASSERTION(info, "cannot create nsGREResProperties"); if (info) { PRBool didLoad = info->DidLoad(); if (!didLoad) { delete info; info = nsnull; } } gNLInfo = info; } } // // See if we are remapping nl_langinfo(CODESET) // if (gNLInfo && nl_langinfo_codeset) { nsAutoString localeKey; #if HAVE_GNU_GET_LIBC_VERSION // // look for an glibc version specific charset remap // const char *glibc_version = gnu_get_libc_version(); if ((glibc_version != nsnull) && (strlen(glibc_version))) { localeKey.AssignLiteral("nllic."); localeKey.AppendWithConversion(glibc_version); localeKey.AppendLiteral("."); localeKey.AppendWithConversion(nl_langinfo_codeset); nsAutoString uCharset; res = gNLInfo->Get(localeKey, uCharset); if (NS_SUCCEEDED(res)) { aCharset.AssignWithConversion(uCharset); res = VerifyCharset(aCharset); if (NS_SUCCEEDED(res)) { oString = aCharset; return res; } } } #endif // // look for a charset specific charset remap // localeKey.AssignLiteral("nllic."); localeKey.AppendWithConversion(nl_langinfo_codeset); nsAutoString uCharset; res = gNLInfo->Get(localeKey, uCharset); if (NS_SUCCEEDED(res)) { aCharset.AssignWithConversion(uCharset); res = VerifyCharset(aCharset); if (NS_SUCCEEDED(res)) { oString = aCharset; return res; } } } NS_ERROR("unable to use nl_langinfo(CODESET)"); #endif // // try falling back on a deprecated (locale based) name // char* locale = setlocale(LC_CTYPE, nsnull); nsAutoString localeStr; localeStr.AssignWithConversion(locale); res = ConvertLocaleToCharsetUsingDeprecatedConfig(localeStr, oString); if (NS_SUCCEEDED(res)) { return res; // succeeded } oString.Truncate(); return res; }
char *platform_get_linux_runtime_os(void) { struct utsname name; FILE *bsd_emul_test; int is_bsd = 0; int ret; int i = 0; if (!got_linux_version) { unlink("emultest.sh"); unlink("emultest.netbsd"); bsd_emul_test = fopen("emultest.sh", "wb"); if (bsd_emul_test) { fprintf(bsd_emul_test, "#!/bin/sh\n"); fprintf(bsd_emul_test, "if test -f /proc/self/emul; then\n"); fprintf(bsd_emul_test, " echo emulation >emultest.netbsd\n"); fprintf(bsd_emul_test, "fi\n"); fclose(bsd_emul_test); chmod("emultest.sh", S_IRWXU); ret = system("./emultest.sh"); if (!ret) { unlink("emultest.sh"); } bsd_emul_test = fopen("emultest.netbsd", "rb"); if (bsd_emul_test) { sprintf(linux_version, "NetBSD"); fclose(bsd_emul_test); unlink("emultest.netbsd"); is_bsd = 1; } } if (!is_bsd) { uname(&name); if (!strcasecmp(name.sysname, "SCO_SV")) { if (name.version[0] == '5' || name.version[0] == '6') { sprintf(linux_version, "lxrun openserver %s", name.version); } else if (name.version[0] == '7') { sprintf(linux_version, "lxrun unixware %s", name.version); } else { sprintf(linux_version, "lxrun sco"); } } else if (!strncasecmp(name.version, "FreeBSD", 7)) { while (name.version[i] != '-' && name.version[i] != 0) { linux_version[i] = name.version[i]; i++; } linux_version[i] = 0; } else { sprintf(linux_version, "%s %s", name.sysname, name.release); } } #ifdef WATCOM_COMPILE #define CLIB_HANDLED sprintf(linux_version, "%s (openwatcom)", linux_version); #endif #if !defined(CLIB_HANDLED) && defined(__dietlibc__) #define CLIB_HANDLED sprintf(linux_version, "%s (dietlibc)", linux_version); #endif #if !defined(CLIB_HANDLED) && defined(_NEWLIB_VERSION) #define CLIB_HANDLED sprintf(linux_version, "%s (newlib %s)", linux_version, _NEWLIB_VERSION); #endif #if !defined(CLIB_HANDLED) && defined(__UCLIBC__) #define CLIB_HANDLED sprintf(linux_version, "%s (uClibc)", linux_version); #endif #if !defined(CLIB_HANDLED) && defined(__GLIBC__) # define CLIB_HANDLED # if (__GLIBC__==2) # if (__GLIBC_MINOR__>0) sprintf(linux_version, "%s (glibc %s)", linux_version, gnu_get_libc_version()); # else sprintf(linux_version, "%s (glibc 2.x)", linux_version); # endif # else sprintf(linux_version, "%s (glibc 1.x)", linux_version); # endif #endif #if !defined(CLIB_HANDLED) && defined(_LINUX_C_LIB_VERSION) # define CLIB_HANDLED sprintf(linux_version, "%s (libc %s)", linux_version, _LINUX_C_LIB_VERSION); #endif #if !defined(CLIB_HANDLED) && (VICE_LINUX_CLIB_VERSION_MAJOR==1) # define CLIB_HANDLED sprintf(linux_version, "%s (glibc 1.x)", linux_version); #endif #if !defined(CLIB_HANDLED) && (VICE_LINUX_CLIB_VERSION_MAJOR==6) # define CLIB_HANDLED sprintf(linux_version, "%s (glibc 2.x)", linux_version); #endif #ifndef CLIB_HANDLED # include <sys/ucontext.h> # ifdef _UCONTEXT_H # define CLIB_HANDLED sprintf(linux_version, "%s (musl)", linux_version); # endif #endif #ifndef CLIB_HANDLED sprintf(linux_version, "%s (unknown libc)", linux_version); #endif got_linux_version = 1; } return linux_version; }
int main(void) { const char *version = gnu_get_libc_version(); return (long)version; }