void zfile_restat (zfile_t *self) { assert (self); struct stat stat_buf; char *real_name = self->link? self->link: self->fullname; if (stat (real_name, &stat_buf) == 0) { self->cursize = stat_buf.st_size; self->modified = stat_buf.st_mtime; self->mode = zsys_file_mode (real_name); self->stable = zsys_file_stable (real_name); } else { if(self->handle) { long cpos = ftell(self->handle); fseek(self->handle, 0L, SEEK_END); self->cursize = ftell(self->handle); fseek(self->handle, cpos, SEEK_SET); } else { self->cursize = 0; } self->modified = 0; self->mode = 0; self->stable = false; } zdigest_destroy (&self->digest); }
int zsys_dir_create (const char *pathname, ...) { va_list argptr; va_start (argptr, pathname); char *formatted = zsys_vprintf (pathname, argptr); va_end (argptr); // Create parent directory levels if needed char *slash = strchr (formatted + 1, '/'); while (true) { if (slash) *slash = 0; // Cut at slash mode_t mode = zsys_file_mode (formatted); if (mode == (mode_t)-1) { // Does not exist, try to create it #if (defined (__WINDOWS__)) if (!CreateDirectoryA (formatted, NULL)) #else if (mkdir (formatted, 0775)) #endif return -1; // Failed } else if ((mode & S_IFDIR) == 0) { // Not a directory, abort } if (!slash) // End if last segment break; *slash = '/'; slash = strchr (slash + 1, '/'); } free (formatted); return 0; }
JNIEXPORT jint JNICALL Java_org_zeromq_czmq_Zsys__1_1fileMode (JNIEnv *env, jclass c, jstring filename) { char *filename_ = (char *) (*env)->GetStringUTFChars (env, filename, NULL); jint file_mode_ = (jint) zsys_file_mode (filename_); (*env)->ReleaseStringUTFChars (env, filename, filename_); return file_mode_; }
static void s_restat (zfile_t *self) { assert (self); struct stat stat_buf; if (stat (self->fullname, &stat_buf) == 0) { self->cursize = stat_buf.st_size; self->modified = stat_buf.st_mtime; self->mode = zsys_file_mode (self->fullname); self->stable = zsys_file_stable (self->fullname); } else { self->cursize = 0; self->modified = 0; self->mode = 0; self->stable = false; } }
void zfile_restat (zfile_t *self) { assert (self); struct stat stat_buf; char *real_name = self->link? self->link: self->fullname; if (stat (real_name, &stat_buf) == 0) { self->cursize = stat_buf.st_size; self->modified = stat_buf.st_mtime; self->mode = zsys_file_mode (real_name); self->stable = zsys_file_stable (real_name); } else { self->cursize = 0; self->modified = 0; self->mode = 0; self->stable = false; } }
bool zsys_file_exists (const char *filename) { assert (filename); return zsys_file_mode (filename) != (mode_t) -1; }
mode_t zfile_mode (const char *filename) { return zsys_file_mode (filename); }
/// // Return file mode; provides at least support for the POSIX S_ISREG(m) // and S_ISDIR(m) macros and the S_IRUSR and S_IWUSR bits, on all boxes. // Returns a mode_t cast to int, or -1 in case of error. int QmlZsysAttached::fileMode (const QString &filename) { return zsys_file_mode (filename.toUtf8().data()); };
void zsys_test (bool verbose) { printf (" * zsys: "); if (verbose) printf ("\n"); // @selftest zsys_catch_interrupts (); // Check capabilities without using the return value int rc = zsys_has_curve (); if (verbose) { char *hostname = zsys_hostname (); zsys_info ("host name is %s", hostname); free (hostname); zsys_info ("system limit is %zd ZeroMQ sockets", zsys_socket_limit ()); } zsys_set_io_threads (1); zsys_set_max_sockets (0); zsys_set_linger (0); zsys_set_sndhwm (1000); zsys_set_rcvhwm (1000); zsys_set_pipehwm (2500); assert (zsys_pipehwm () == 2500); zsys_set_ipv6 (0); rc = zsys_file_delete ("nosuchfile"); assert (rc == -1); bool rc_bool = zsys_file_exists ("nosuchfile"); assert (rc_bool != true); rc = (int) zsys_file_size ("nosuchfile"); assert (rc == -1); time_t when = zsys_file_modified ("."); assert (when > 0); mode_t mode = zsys_file_mode ("."); assert (S_ISDIR (mode)); assert (mode & S_IRUSR); assert (mode & S_IWUSR); zsys_file_mode_private (); rc = zsys_dir_create ("%s/%s", ".", ".testsys/subdir"); assert (rc == 0); when = zsys_file_modified ("./.testsys/subdir"); assert (when > 0); assert (!zsys_file_stable ("./.testsys/subdir")); rc = zsys_dir_delete ("%s/%s", ".", ".testsys/subdir"); assert (rc == 0); rc = zsys_dir_delete ("%s/%s", ".", ".testsys"); assert (rc == 0); zsys_file_mode_default (); int major, minor, patch; zsys_version (&major, &minor, &patch); assert (major == CZMQ_VERSION_MAJOR); assert (minor == CZMQ_VERSION_MINOR); assert (patch == CZMQ_VERSION_PATCH); char *string = zsys_sprintf ("%s %02x", "Hello", 16); assert (streq (string, "Hello 10")); free (string); char *str64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890,."; int num10 = 1234567890; string = zsys_sprintf ("%s%s%s%s%d", str64, str64, str64, str64, num10); assert (strlen (string) == (4 * 64 + 10)); free (string); // Test logging system zsys_set_logident ("czmq_selftest"); zsys_set_logsender ("inproc://logging"); void *logger = zsys_socket (ZMQ_SUB, NULL, 0); assert (logger); rc = zsocket_connect (logger, "inproc://logging"); assert (rc == 0); rc = zmq_setsockopt (logger, ZMQ_SUBSCRIBE, "", 0); assert (rc == 0); if (verbose) { zsys_error ("This is an %s message", "error"); zsys_warning ("This is a %s message", "warning"); zsys_notice ("This is a %s message", "notice"); zsys_info ("This is a %s message", "info"); zsys_debug ("This is a %s message", "debug"); zsys_set_logident ("hello, world"); zsys_info ("This is a %s message", "info"); zsys_debug ("This is a %s message", "debug"); // Check that logsender functionality is working char *received = zstr_recv (logger); assert (received); zstr_free (&received); } zsys_close (logger, NULL, 0); // @end printf ("OK\n"); }
/// // Return file mode; provides at least support for the POSIX S_ISREG(m) // and S_ISDIR(m) macros and the S_IRUSR and S_IWUSR bits, on all boxes. // Returns a mode_t cast to int, or -1 in case of error. int QZsys::fileMode (const QString &filename) { int rv = zsys_file_mode (filename.toUtf8().data()); return rv; }