int main(int argc, char *argv[]) { int flags, opt; mqd_t mqd; unsigned int prio; flags = O_WRONLY; while ((opt = getopt(argc, argv, "n")) != -1) { switch (opt) { case 'n': flags |= O_NONBLOCK; break; default: usageError(argv[0]); } } if (optind + 1 >= argc) usageError(argv[0]); mqd = mq_open(argv[optind], flags); if (mqd == (mqd_t) -1) errExit("mq_open"); prio = (argc > optind + 2) ? atoi(argv[optind + 2]) : 0; if (mq_send(mqd, argv[optind + 1], strlen(argv[optind + 1]), prio) == -1) errExit("mq_send"); exit(EXIT_SUCCESS); }
static char *parseArgs(int argc, char *argv[]) { char *name = "mpsio.log"; int i = 1; if (argc >= 1) prog = argv[0]; else prog = "unknown"; while (i < argc) { /* consider argument i */ if (argv[i][0] == '-') { /* it's an option argument */ switch (argv[i][1]) { case 'f': /* file name */ ++ i; if (i == argc) usageError(); else name = argv[i]; break; case 'p': /* partial log */ partialLog = TRUE; break; case '?': case 'h': /* help */ usage(); break; default: usageError(); } } /* if option */ ++ i; } return name; }
int main(int argc, char *argv[]) { int flags, opt; mode_t perms; unsigned int value; sem_t *sem; flags = 0; 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 >= argc) usageError(argv[0]); /* Default permissions are rw-------; default semaphore initialization value is 0 */ perms = (argc <= optind + 1) ? (S_IRUSR | S_IWUSR) : getInt(argv[optind + 1], GN_BASE_8, "octal-perms"); value = (argc <= optind + 2) ? 0 : getInt(argv[optind + 2], 0, "value"); sem = sem_open(argv[optind], flags, perms, value); if (sem == SEM_FAILED) errExit("sem_open"); exit(EXIT_SUCCESS); }
int main(int argc,char *argv[]) { char list[XATTR_SIZE],value[XATTR_SIZE]; ssize_t listLen,valueLen; int ns,j,k,opt; Boolean hexDisplay; hexDisplay = 0; while((opt = getopt(argc,argv,"x")) != -1) { switch (opt) { case 'x':hexDisplay = 1;break; case '?': usageError(argv[0]); } } if (optind >= argc + 2) { usageError(argv[0]); } for (j = optind; j < argc; j++) { listLen = listxattr(argv[j],list,XATTR_SIZE); if (listLen == -1) { errExit("listxattr\n"); } printf("%s:\n",argv[j]); /* Loop through all EA names,displaying name + value */ for (ns = 0; ns < listLen; ns += strlen(&list[ns]) + 1) { printf(" name=%s;",&list[ns]); valueLen = getxattr(argv[j],&list[ns],value,XATTR_SIZE); if (valueLen == -1) { printf("couldn't get value"); }else if (!hexDisplay) { printf("value=%.*s",(int)valueLen,value); }else { printf("value="); for (k = 0; k < valueLen; k++) { printf("%02x",(unsigned int)value[k]); } } printf("\n"); } printf("\n"); } exit(EXIT_SUCCESS); }
static void parseArgs(int argc, char *argv[]) { int i = 1; if (argc >= 1) prog = argv[0]; else prog = "unknown"; while (i < argc) { /* consider argument i */ if (argv[i][0] == '-') { /* it's an option argument */ switch (argv[i][1]) { case 'l': /* log file name */ ++ i; if (i == argc) usageError(); else logFileName = argv[i]; break; case '?': case 'h': /* help */ usage(); exit(EXIT_SUCCESS); default: usageError(); } } /* if option */ ++ i; } }
int main(int argc, char *argv[]) { int flags, opt; flags = 0; while ((opt = getopt(argc, argv, "dmp")) != -1) { switch (opt) { case 'd': flags |= FTW_DEPTH; break; case 'm': flags |= FTW_MOUNT; break; case 'p': flags |= FTW_PHYS; break; default: usageError(argv[0], NULL); } } if (argc > optind + 1) usageError(argv[0], NULL); if (nftw((argc > optind) ? argv[optind] : ".", dirTree, 10, flags) == -1) { perror("nftw"); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { int opt, xfnd; char *pstr; xfnd = 0; pstr = NULL; while ((opt = getopt(argc, argv, ":p:x")) != -1) { printf("opt =%3d (%c); optind = %d", opt, printable(opt), optind); if (opt == '?' || opt == ':') printf("; optopt =%3d (%c)", optopt, printable(optopt)); printf("\n"); switch (opt) { case 'p': pstr = optarg; break; case 'x': xfnd++; break; case ':': usageError(argv[0], "Missing argument", optopt); case '?': usageError(argv[0], "Unrecognized option", optopt); default: fatal("Unexpected case in switch()"); } } if (xfnd != 0) printf("-x was specified (count=%d)\n", xfnd); if (pstr != NULL) printf("-p was specified with the value \"%s\"\n", pstr); if (optind < argc) printf("First nonoption argument is \"%s\" at argv[%d]\n", argv[optind], optind); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { int flags, opt; mode_t perms; mqd_t mqd; struct mq_attr attr, *attrp; /* If 'attrp' is NULL, mq_open() uses default attributes. If an option specifying a message queue attribute is supplied on the command line, we save the attribute in 'attr' and set 'attrp' pointing to 'attr'. We assign some (arbitrary) default values to the fields of 'attr' in case the user specifies the value for one of the queue attributes, but not the other. */ attrp = NULL; attr.mq_maxmsg = 50; attr.mq_msgsize = 2048; flags = O_RDWR; /* Parse command-line options */ while ((opt = getopt(argc, argv, "cm:s:x")) != -1) { switch (opt) { case 'c': flags |= O_CREAT; break; case 'm': attr.mq_maxmsg = atoi(optarg); attrp = &attr; break; case 's': attr.mq_msgsize = atoi(optarg); attrp = &attr; break; case 'x': flags |= O_EXCL; break; default: usageError(argv[0]); } } if (optind >= argc) usageError(argv[0]); perms = (argc <= optind + 1) ? (S_IRUSR | S_IWUSR) : getInt(argv[optind + 1], GN_BASE_8, "octal-perms"); mqd = mq_open(argv[optind], flags, perms, attrp); if (mqd == (mqd_t) -1) errExit("mq_open"); exit(EXIT_SUCCESS); }
static char *parseArgs(int argc, char *argv[]) { char *name = "mpsio.log"; int i = 1; if (argc >= 1) prog = argv[0]; else prog = "unknown"; while (i < argc) { /* consider argument i */ if (argv[i][0] == '-') { /* it's an option argument */ switch (argv[i][1]) { case 'f': /* file name */ ++ i; if (i == argc) usageError(); else name = argv[i]; break; case 'p': /* partial log */ partialLog = TRUE; break; case 'v': /* verbosity */ verbose = TRUE; break; case 'e': { /* event statistics */ reportEvents = TRUE; ++ i; if (i == argc) usageError(); else parseEventSpec(argv[i]); } break; case 'b': { /* bucket size */ ++ i; if (i == argc) usageError(); else { int n; n = sscanf(argv[i], "%lu", &bucketSize); if (n != 1) usageError(); } } break; case 'S': /* style */ style = argv[i][2]; /* '\0' for human-readable, 'L' for Lisp, */ break; /* 'C' for CDF. */ case '?': case 'h': /* help */ usage(); break; default: usageError(); } } /* if option */ ++ i; } return name; }
int main(int argc, char *argv[]) { int attr, oldAttr, j, fd; char *p; if (argc < 3 || strchr("+-=", argv[1][0]) == NULL || strcmp(argv[1], "--help") == 0) usageError(argv[0]); /* Build bit mask based on attribute string in argv[1] */ attr = 0; for (p = &argv[1][1]; *p != '\0'; p++) { switch (*p) { case 'a': attr |= FS_APPEND_FL; break; case 'A': attr |= FS_NOATIME_FL; break; case 'c': attr |= FS_COMPR_FL; break; case 'd': attr |= FS_NODUMP_FL; break; case 'D': attr |= FS_DIRSYNC_FL; break; case 'i': attr |= FS_IMMUTABLE_FL; break; case 'j': attr |= FS_JOURNAL_DATA_FL; break; case 's': attr |= FS_SECRM_FL; break; case 'S': attr |= FS_SYNC_FL; break; case 't': attr |= FS_NOTAIL_FL; break; case 'T': attr |= FS_TOPDIR_FL; break; case 'u': attr |= FS_UNRM_FL; break; default: usageError(argv[0]); } } /* Open each filename in turn, and change its attributes */ for (j = 2; j < argc; j++) { fd = open(argv[j], O_RDONLY); if (fd == -1) { /* Most likely error is nonexistent file */ errMsg("open: %s", argv[j]); continue; } /* If argv[1] starts with + or -, then retrieve existing attribute bit mask and modify as required */ if (argv[1][0] == '+' || argv[1][0] == '-') { if (ioctl(fd, FS_IOC_GETFLAGS, &oldAttr) == -1) errExit("ioctl1: %s", argv[j]); attr = (*argv[1] == '-') ? (oldAttr & ~attr) : (oldAttr | attr); } if (ioctl(fd, FS_IOC_SETFLAGS, &attr) == -1) errExit("ioctl2: %s", argv[j]); if (close(fd) == -1) errExit("close"); } exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { unsigned long flags; char *data, *fstype; int j, opt; flags = 0; data = NULL; fstype = NULL; while ((opt = getopt(argc, argv, "o:t:f:")) != -1) { switch (opt) { case 'o': data = optarg; break; case 't': fstype = optarg; break; case 'f': for (j = 0; j < strlen(optarg); j++) { switch (optarg[j]) { case 'b': flags |= MS_BIND; break; case 'd': flags |= MS_DIRSYNC; break; case 'l': flags |= MS_MANDLOCK; break; case 'm': flags |= MS_MOVE; break; case 'A': flags |= MS_NOATIME; break; case 'V': flags |= MS_NODEV; break; case 'D': flags |= MS_NODIRATIME; break; case 'E': flags |= MS_NOEXEC; break; case 'S': flags |= MS_NOSUID; break; case 'r': flags |= MS_RDONLY; break; case 'c': flags |= MS_REC; break; case 'R': flags |= MS_REMOUNT; break; case 's': flags |= MS_SYNCHRONOUS; break; default: usageError(argv[0], NULL); } } break; default: usageError(argv[0], NULL); } } if (argc != optind + 2) usageError(argv[0], "Wrong number of arguments\n"); if (mount(argv[optind], argv[optind + 1], fstype, flags, data) == -1) errExit("mount"); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { int msqid, flags, type; ssize_t msgLen; size_t maxBytes; struct mbuf msg; /* Message buffer for msgrcv() */ int opt; /* Option character from getopt() */ /* Parse command-line options and arguments */ flags = 0; type = 0; while ((opt = getopt(argc, argv, "ent:x")) != -1) { switch (opt) { case 'e': flags |= MSG_NOERROR; break; case 'n': flags |= IPC_NOWAIT; break; case 't': type = atoi(optarg); break; #ifdef MSG_EXCEPT case 'x': flags |= MSG_EXCEPT; break; #endif default: usageError(argv[0], NULL); } } if (argc < optind + 1 || argc > optind + 2) usageError(argv[0], "Wrong number of arguments\n"); msqid = getInt(argv[optind], 0, "msqid"); maxBytes = (argc > optind + 1) ? getInt(argv[optind + 1], 0, "max-bytes") : MAX_MTEXT; /* Get message and display on stdout */ msgLen = msgrcv(msqid, &msg, maxBytes, type, flags); if (msgLen == -1) errExit("msgrcv"); printf("Received: type=%ld; length=%ld", msg.mtype, (long) msgLen); if (msgLen > 0) printf("; body=%s", msg.mtext); printf("\n"); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { int level, options, opt; options = 0; level = LOG_INFO; while ((opt = getopt(argc, argv, "l:pe")) != -1) { switch (opt) { case 'l': switch (optarg[0]) { case 'g': level = LOG_EMERG; break; case 'a': level = LOG_ALERT; break; case 'c': level = LOG_CRIT; break; case 'e': level = LOG_ERR; break; case 'w': level = LOG_WARNING; break; case 'n': level = LOG_NOTICE; break; case 'i': level = LOG_INFO; break; case 'd': level = LOG_DEBUG; break; default: cmdLineErr("Bad level: %c\n", optarg[0]); } break; case 'p': options |= LOG_PID; break; #if ! defined(__hpux) && ! defined(__sun) /* Not on HP-UX 11 or Solaris 8 */ case 'e': options |= LOG_PERROR; break; #endif default: fprintf(stderr, "Bad option\n"); usageError(argv[0]); } } if (argc != optind + 1) usageError(argv[0]); openlog(argv[0], options, LOG_USER); syslog(LOG_USER | level, "%s", argv[optind]); closelog(); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { int flags, opt; mode_t perms; mqd_t mqd; struct mq_attr attr, *attrp; attrp = NULL; attr.mq_maxmsg = 50; attr.mq_msgsize = 2048; flags = O_RDWR; /* Parse command-line options */ while ((opt = getopt(argc, argv, "cm:s:x")) != -1) { switch (opt) { case 'c': flags |= O_CREAT; break; case 'm': attr.mq_maxmsg = atoi(optarg); attrp = &attr; break; case 's': attr.mq_msgsize = atoi(optarg); attrp = &attr; break; case 'x': flags |= O_EXCL; break; default: usageError(argv[0]); } } if (optind >= argc) usageError(argv[0]); perms = (argc <= optind + 1) ? (S_IRUSR | S_IWUSR) : getInt(argv[optind + 1], GN_BASE_8, "octal-perms"); mqd = mq_open(argv[optind], flags, perms, attrp); if (mqd == (mqd_t) -1) errExit("mq_open"); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { void *addr; char *retAddr, *p; int j, flags, shmid; printf("SHMLBA = %ld (%#lx), PID = %ld\n", (long) SHMLBA, (unsigned long) SHMLBA, (long) getpid()); for (j = 1; j < argc; j++) { shmid = strtol(argv[j], &p, 0); if (*p != ':') usageError(argv[0]); addr = (void *) strtol(p + 1, NULL, 0); flags = (strchr(p + 1, 'r') != NULL) ? SHM_RND : 0; if (strchr(p + 1, 'R') != NULL) flags |= SHM_RDONLY; retAddr = shmat(shmid, addr, flags); if (retAddr == (void *) -1) errExit("shmat: %s", argv[j]); printf("%d: %s ==> %p\n", j, argv[j], retAddr); } printf("Sleeping 5 seconds\n"); sleep(5); exit(EXIT_SUCCESS); }
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); }
int main(int argc, char *argv[]) { int msqid, flags, msgLen; struct mbuf msg; /* Message buffer for msgsnd() */ int opt; /* Option character from getopt() */ /* Parse command-line options and arguments */ flags = 0; while ((opt = getopt(argc, argv, "n")) != -1) { if (opt == 'n') flags |= IPC_NOWAIT; else usageError(argv[0], NULL); } if (argc < optind + 2 || argc > optind + 3) usageError(argv[0], "Wrong number of arguments\n"); msqid = getInt(argv[optind], 0, "msqid"); msg.mtype = getInt(argv[optind + 1], 0, "msg-type"); if (argc > optind + 2) /* 'msg-text' was supplied */ { msgLen = strlen(argv[optind + 2]) + 1; if (msgLen > MAX_MTEXT) cmdLineErr("msg-text too long (max: %d characters)\n", MAX_MTEXT); memcpy(msg.mtext, argv[optind + 2], msgLen); } else /* No 'msg-text' ==> zero-length msg */ { msgLen = 0; } /* Send message */ if (msgsnd(msqid, &msg, msgLen, flags) == -1) errExit("msgsnd"); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { int flags, opt; mqd_t mqd; unsigned int prio; void *buffer; struct mq_attr attr; ssize_t numRead; flags = O_RDONLY; while ((opt = getopt(argc, argv, "n")) != -1) { switch (opt) { case 'n': flags |= O_NONBLOCK; break; default: usageError(argv[0]); } } if (optind >= argc) usageError(argv[0]); mqd = mq_open(argv[optind], flags); if (mqd == (mqd_t) -1) errExit("mq_open"); if (mq_getattr(mqd, &attr) == -1) errExit("mq_getattr"); buffer = malloc(attr.mq_msgsize); if (buffer == NULL) errExit("malloc"); numRead = mq_receive(mqd, buffer, attr.mq_msgsize, &prio); if (numRead == -1) errExit("mq_receive"); printf("Read %ld bytes; priority = %u\n", (long) numRead, prio); if (write(STDOUT_FILENO, buffer, numRead) == -1) errExit("write"); write(STDOUT_FILENO, "\n", 1); exit(EXIT_SUCCESS); }
// lol int main(int argc, char *argv) { if (argc < 4) { usageError("%s file name value\n", argv[0]); } if (setxattr(argv[1], argv[2], argv[3], strlen(argv[3])) == -1) { errExit("setxattr"); } exit(EXIT_SUCCESS); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int primitiveIndex = 0; GLenum primitive = GL_POINTS; int doRasterizerDiscard = 0; int status; GLenum error = GL_NO_ERROR; dotsMglClearGLErrors(); // check for transform feedback extension! if (!dotsMglIsExtensionSupported(EXTENSION)){ plhs[0] = mxCreateDoubleScalar(-1); mexPrintf("(dotsMglBeginTransformFeedback) %s is not supported!\n", EXTENSION); return; } // check input arguments if (nrhs < 1 || nrhs > 2 || !mxIsDouble(prhs[0]) || mxIsEmpty(prhs[0])) { plhs[0] = mxCreateDoubleScalar(-2); usageError("dotsMglBeginTransformFeedback"); return; } // choose kind of primitive will be captured primitiveIndex = mxGetScalar(prhs[0]); if (primitiveIndex >= 0 && primitiveIndex < NUM_GL_PRIMITIVES) primitive = GL_PRIMITIVES[primitiveIndex]; // choose to truncate the GL pipeline or allow drawing if (nrhs >= 2 && mxIsDouble(prhs[1]) && !mxIsEmpty(prhs[1])) { if (mxGetScalar(prhs[1])) glEnable(GL_RASTERIZER_DISCARD_EXT); else glDisable(GL_RASTERIZER_DISCARD_EXT); } // start capturing varyings glBeginTransformFeedbackEXT(primitive); error = glGetError(); if (error != GL_NO_ERROR) { mexPrintf("(dotsMglSelectTransformFeedback) Could not begin transform feedback for primitive index %d (primitive=%d). glGetError()=%d\n", primitiveIndex, primitive, error); plhs[0] = mxCreateDoubleScalar(-3); return; } // success! plhs[0] = mxCreateDoubleScalar(0); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int status; GLuint programID = 0; GLenum error = GL_NO_ERROR; dotsMglClearGLErrors(); // check input arguments if (nrhs > 1) { usageError("dotsMglUseShaderProgram"); plhs[0] = mxCreateDoubleScalar(-1); return; } if (nrhs < 1 || mxIsEmpty(prhs[0])) { // empty input means revert to OpenGL fixed pipeline glUseProgram(0); } else if(mxIsStruct(prhs[0])) { // info struct describing OpenGL shader program programID = (GLuint)dotsMglGetInfoScalar(prhs[0], 0, "programID", &status); if (status >= 0) glUseProgram(programID); } error = glGetError(); if (error != GL_NO_ERROR) { mexPrintf("(dotsMglUseShaderProgram) Could not use program. glGetError()=%d\n", error); plhs[0] = mxCreateDoubleScalar(-2); return; } // success! programID >= 0 plhs[0] = mxCreateDoubleScalar(programID); }
int main(int argc, char *argv[]) { struct sembuf sops[MAX_SEMOPS]; int ind, nsops; if (argc < 2 || strcmp(argv[1], "--help") == 0) usageError(argv[0]); for (ind = 2; argv[ind] != NULL; ind++) { nsops = parseOps(argv[ind], sops); printf("%5ld, %s: about to semop() [%s]\n", (long) getpid(), currTime("%T"), argv[ind]); if (semop(getInt(argv[1], 0, "semid"), sops, nsops) == -1) errExit("semop (PID=%ld)", (long) getpid()); printf("%5ld, %s: semop() completed [%s]\n", (long) getpid(), currTime("%T"), argv[ind]); } exit(EXIT_SUCCESS); }
void leaky::initialize(int argc, char** argv) { applicationName = argv[0]; applicationName = strrchr(applicationName, '/'); if (!applicationName) { applicationName = argv[0]; } else { applicationName++; } int arg; int errflg = 0; int longindex = 0; onlyThread = 0; output_dir = NULL; cleo = false; // XXX tons of cruft here left over from tracemalloc // XXX The -- options shouldn't need short versions, or they should be documented while (((arg = getopt_long(argc, argv, "adEe:gh:i:r:Rs:tT:qvx:ln:",longopts,&longindex)) != -1)) { switch (arg) { case '?': default: fprintf(stderr,"error: unknown option %c\n",optopt); errflg++; break; case 'a': break; case 'A': // not implemented showAddress = true; break; case 'c': cleo = true; break; case 'd': output_dir = optarg; // reference to an argv pointer break; case 'R': break; case 'e': exclusions.add(optarg); break; case 'g': break; case 'r': // not implemented roots.add(optarg); if (!includes.IsEmpty()) { errflg++; } break; case 'i': includes.add(optarg); if (!roots.IsEmpty()) { errflg++; } break; case 'h': break; case 's': stackDepth = atoi(optarg); if (stackDepth < 2) { stackDepth = 2; } break; case 'x': // --start collect_start = atoi(optarg); break; case 'n': // --end collect_end = atoi(optarg); break; case 'l': // --last collect_last = true; break; case 'q': break; case 'v': quiet = !quiet; break; case 't': showThreads = true; break; case 'T': showThreads = true; onlyThread = atoi(optarg); break; } } if (errflg || ((argc - optind) < 2)) { usageError(); } progFile = argv[optind++]; logFileIndex = optind; numLogFiles = argc - optind; if (!quiet) fprintf(stderr,"numlogfiles = %d\n",numLogFiles); }
void leaky::initialize(int argc, char** argv) { applicationName = argv[0]; applicationName = strrchr(applicationName, '/'); if (!applicationName) { applicationName = argv[0]; } else { applicationName++; } int arg; int errflg = 0; while ((arg = getopt(argc, argv, "adEe:gh:i:r:Rs:tqx")) != -1) { switch (arg) { case '?': errflg++; break; case 'a': break; case 'A': showAddress = TRUE; break; case 'd': break; case 'R': break; case 'e': exclusions.add(optarg); break; case 'g': break; case 'r': roots.add(optarg); if (!includes.IsEmpty()) { errflg++; } break; case 'i': includes.add(optarg); if (!roots.IsEmpty()) { errflg++; } break; case 'h': break; case 's': stackDepth = atoi(optarg); if (stackDepth < 2) { stackDepth = 2; } break; case 'x': break; case 'q': quiet = TRUE; break; } } if (errflg || ((argc - optind) < 2)) { usageError(); } progFile = argv[optind++]; logFile = argv[optind]; }
int main(int argc,char *argv[]) { acl_t acl; acl_type_t type; acl_entry_t entry; acl_tag_t tag; uid_t *uidp; gid_t *gidp; acl_permset_t permset; char *name; int entryId,permVal,opt; type = ACL_TYPE_ACCESS; while((opt = getopt(argc,argv,"d") != -1)) { switch(opt) { case 'd': type = ACL_TYPE_DEFAULT;break; case '?': usageError(argv[0]); } } if (optind + 1 != argc) { usageError(argv[0]); } acl = acl_get_file(argv[optind],type); if (acl == NULL) { errExit("acl_get_file"); } /* Walk through each entry in this ACL */ for (entryId = ACL_FIRST_ENTRY; ; entryId = ACL_NEXT_ENTRY) { if (acl_get_entry(acl,entryId,&entry) != 1) { break; /* Exit on error or no more entries */ } /* Retrieve and display tag type */ if (acl_get_tag_type(entry,&tag) == -1) { errExit("acl_get_tag_type"); } printf("%-12s", (tag == ACL_USER_OBJ) ? "user_obj" : (tag == ACL_USER) ? "user" : (tag == ACL_GROUP_OBJ) ? "group_obj": (tag == ACL_GROUP) ? "group": (tag == ACL_MASK) ? "mask": (tag == ACL_OTHER) ? "other":"???"); /* Retrieve and display otpional tag qualifier */ if (tag == ACL_USER) { uidp = acl_get_qualifier(entry); if (uidp == NULL) { errExit("acl_get_qualifier"); } name = userNameFromId(*uidp); if (name == NULL) { printf("%-8d",*uidp); } else { printf("%-8s",name); } if (acl_free(uidp) == -1) { errExit("acl_free"); } }else if (tag == ACL_GROUP) { gidp = acl_get_qualifier(entry); if (gidp == NULL) { errExit("acl_get_qualifier"); } name = groupNameFromId(*gidp); if (name == NULL) { printf("%-12d",*gidp); } else { printf("%-12s",name); } if (acl_free(gidp) == -1) { errExit("acl_free"); } }else { printf(" "); } /* Retrieve and display permissions */ if (acl_get_permset(entry,&permset) == -1) { errExit("acl_get_permset"); } permVal = acl_get_perm(permset,ACL_READ); if (permVal == -1) { errExit("acl_get_perm - ACL_READ"); } printf("%c", (permVal == 1) ? 'r' : '-'); permVal = acl_get_perm(permset,ACL_WRITE); if (permVal == -1) { errExit("acl_get_perm -ACL_WRITE"); } printf("%c", (permVal == 1) ? 'w': '-'); permVal = acl_get_perm(permset,ACL_EXECUTE); if (permVal == -1) { errExit("acl_get_perm - ACL_EXECUTE"); } printf("%c", (permVal == 1) ? 'x' : '-'); printf("\n"); } if (acl_free(acl) == -1) { errExit("acl_free"); } exit(EXIT_SUCCESS); }
MAIN(appweb, int argc, char **argv, char **envp) { Mpr *mpr; cchar *argp, *jail; char *logSpec, *traceSpec; int argind; jail = 0; logSpec = 0; traceSpec = 0; if ((mpr = mprCreate(argc, argv, MPR_USER_EVENTS_THREAD)) == NULL) { exit(1); } if ((app = mprAllocObj(AppwebApp, manageApp)) == NULL) { exit(2); } mprAddRoot(app); mprAddStandardSignals(); #if ME_ROM extern MprRomInode romFiles[]; mprSetRomFileSystem(romFiles); #endif if (httpCreate(HTTP_CLIENT_SIDE | HTTP_SERVER_SIDE) == 0) { exit(3); } app->mpr = mpr; app->workers = -1; app->home = sclone(ME_SERVER_ROOT); app->documents = app->home; argc = mpr->argc; argv = (char**) mpr->argv; for (argind = 1; argind < argc; argind++) { argp = argv[argind]; if (*argp != '-') { break; } if (smatch(argp, "--config") || smatch(argp, "--conf")) { if (argind >= argc) { usageError(); } app->configFile = sclone(argv[++argind]); #if ME_UNIX_LIKE } else if (smatch(argp, "--chroot")) { if (argind >= argc) { usageError(); } jail = mprGetAbsPath(argv[++argind]); #endif } else if (smatch(argp, "--debugger") || smatch(argp, "-D")) { mprSetDebugMode(1); } else if (smatch(argp, "--exe")) { if (argind >= argc) { usageError(); } mpr->argv[0] = mprGetAbsPath(argv[++argind]); mprSetAppPath(mpr->argv[0]); mprSetModuleSearchPath(NULL); } else if (smatch(argp, "--home")) { if (argind >= argc) { usageError(); } app->home = sclone(argv[++argind]); if (chdir(app->home) < 0) { mprLog("error appweb", 0, "Cannot change directory to %s", app->home); exit(4); } } else if (smatch(argp, "--log") || smatch(argp, "-l")) { if (argind >= argc) { usageError(); } logSpec = argv[++argind]; } else if (smatch(argp, "--name") || smatch(argp, "-n")) { if (argind >= argc) { usageError(); } mprSetAppName(argv[++argind], 0, 0); } else if (smatch(argp, "--threads")) { if (argind >= argc) { usageError(); } app->workers = atoi(argv[++argind]); } else if (smatch(argp, "--show") || smatch(argp, "-s")) { app->show = 1; } else if (smatch(argp, "--trace") || smatch(argp, "-t")) { if (argind >= argc) { usageError(); } traceSpec = argv[++argind]; } else if (smatch(argp, "--verbose") || smatch(argp, "-v")) { if (!logSpec) { logSpec = sfmt("stderr:2"); } if (!traceSpec) { traceSpec = sfmt("stderr:2"); } } else if (smatch(argp, "--version") || smatch(argp, "-V")) { mprPrintf("%s\n", ME_VERSION); exit(0); } else if (*argp == '-' && isdigit((uchar) argp[1])) { if (!logSpec) { logSpec = sfmt("stderr:%d", (int) stoi(&argp[1])); } if (!traceSpec) { traceSpec = sfmt("stderr:%d", (int) stoi(&argp[1])); } } else if (smatch(argp, "-?") || scontains(argp, "-help")) { usageError(); exit(5); } else if (*argp == '-') { mprLog("error appweb", 0, "Unknown switch \"%s\"", argp); usageError(); exit(5); } } app->home = mprGetAbsPath(app->home); if (logSpec) { mprStartLogging(logSpec, MPR_LOG_DETAILED | MPR_LOG_CONFIG | MPR_LOG_CMDLINE); } if (traceSpec) { httpStartTracing(traceSpec); } if (mprStart() < 0) { mprLog("error appweb", 0, "Cannot start MPR"); mprDestroy(); return MPR_ERR_CANT_INITIALIZE; } if (checkEnvironment(argv[0]) < 0) { exit(6); } if (argc == argind && !app->configFile) { if (findAppwebConf() < 0) { exit(7); } } if (jail && changeRoot(jail) < 0) { exit(8); } if (createEndpoints(argc - argind, &argv[argind]) < 0) { return MPR_ERR_CANT_INITIALIZE; } if (maStartAppweb(app->appweb) < 0) { mprLog("error appweb", 0, "Cannot start HTTP service, exiting."); exit(9); } if (app->show) { httpLogRoutes(0, 0); } mprServiceEvents(-1, 0); mprLog("info appweb", 1, "Stopping Appweb ..."); mprDestroy(); return mprGetExitStatus(); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { GLuint bufferID = 0; GLenum usage = GL_STREAM_DRAW; GLenum target = GL_ARRAY_BUFFER; GLenum access = GL_WRITE_ONLY; GLenum error = GL_NO_ERROR; int status; void* glDataPtr = NULL; void* mxDataPtr = NULL; mxArray* mxData = NULL; mxClassID mxClass = mxDOUBLE_CLASS; size_t nElements = 0; size_t nBytes = 0; size_t offsetElements = 0; size_t nRangeElements = 0; size_t offsetBytes = 0; size_t nRangeBytes = 0; GLboolean isMapSuccess = GL_FALSE; int doReallocate = 0; dotsMglClearGLErrors(); // check input arguments if (nrhs < 2 || nrhs > 4 || !mxIsStruct(prhs[0]) || mxIsEmpty(prhs[0]) || !mxIsNumeric(prhs[1]) || mxIsEmpty(prhs[1])) { plhs[0] = mxCreateDoubleScalar(-1); usageError("dotsMglWriteToVertexBufferObject"); return; } // get basic info about VBO bufferID = (GLuint)dotsMglGetInfoScalar(prhs[0], 0, "bufferID", &status); if (status < 0) { plhs[0] = mxCreateDoubleScalar(-2); return; } target = (GLenum)dotsMglGetInfoScalar(prhs[0], 0, "target", &status); if (status < 0) { plhs[0] = mxCreateDoubleScalar(-2); return; } usage = (GLenum)dotsMglGetInfoScalar(prhs[0], 0, "usage", &status); if (status < 0) { plhs[0] = mxCreateDoubleScalar(-2); return; } nElements = (size_t)dotsMglGetInfoScalar(prhs[0], 0, "nElements", &status); if (status < 0) { plhs[0] = mxCreateDoubleScalar(-2); return; } nBytes = (size_t)dotsMglGetInfoScalar(prhs[0], 0, "nBytes", &status); if (status < 0) { plhs[0] = mxCreateDoubleScalar(-2); return; } mxData = mxGetField(prhs[0], 0, "mxData"); if (mxData == NULL) { mexPrintf("(dotsMglWriteToVertexBufferObject) Can not locate original data (needed as template).\n"); plhs[0] = mxCreateDoubleScalar(-2); return; } mxClass = mxGetClassID(mxData); // does this incoming data class match the original class? if (mxClass != mxGetClassID(prhs[1])){ mexPrintf("(dotsMglWriteToVertexBufferObject) Class of given data (%d) does not match class of VBO data (%d).\n", mxGetClassID(prhs[1]), mxClass); plhs[0] = mxCreateDoubleScalar(-6); return; } // get basic info about input data nRangeElements = (size_t)mxGetNumberOfElements(prhs[1]); mxDataPtr = mxGetData(prhs[1]); // choose the range offset (expect 0-based offset) if (nrhs >= 3 && mxIsNumeric(prhs[2]) && !mxIsEmpty(prhs[2])) offsetElements = (size_t)mxGetScalar(prhs[2]); if ((offsetElements + nRangeElements) > nElements){ mexPrintf("(dotsMglWriteToVertexBufferObject) Range offset=%d plus number of elements=%d exceeds VBO nElements-1=%d.\n", offsetElements, nRangeElements, nElements-1); plhs[0] = mxCreateDoubleScalar(-7); return; } // choose whether to reallocate the buffer storage if (nrhs >= 4 && mxIsNumeric(prhs[3]) && !mxIsEmpty(prhs[3])) doReallocate = (int)mxGetScalar(prhs[3]); // bind the buffer to its target, which makes it accessible glBindBuffer(target, bufferID); // may reallocate or "orphan" the VBO // instead of waiting for safe access if (doReallocate > 0) glBufferData(target, nBytes, NULL, usage); // map the entire buffer for writing glDataPtr = glMapBuffer(target, access); if (glDataPtr == NULL) { error = glGetError(); mexPrintf("(dotsMglWriteToVertexBufferObject) Could not map VBO for target=%d. glGetError()=%d\n", target, error); plhs[0] = mxCreateDoubleScalar(-8); return; } // copy input data to VBO offsetBytes = offsetElements*mxGetElementSize(prhs[1]); nRangeBytes = nRangeElements*mxGetElementSize(prhs[1]); if ((offsetBytes + nRangeBytes) > nBytes){ mexPrintf("(dotsMglWriteToVertexBufferObject) Range offset %d plus number of bytes %d exceeds VBO nBytes-1 %d.\n", offsetBytes, nRangeBytes, nBytes-1); plhs[0] = mxCreateDoubleScalar(-9); return; } memcpy(glDataPtr+offsetBytes, mxDataPtr, nRangeBytes); // unmap the entire buffer isMapSuccess = glUnmapBuffer(target); glBindBuffer(target, 0); if(isMapSuccess == GL_FALSE) { error = glGetError(); mexPrintf("(dotsMglWriteToVertexBufferObject) Writing VBO for target=%d caused data corruption! glGetError()=%d\n", target, error); mxDestroyArray(plhs[0]); plhs[0] = mxCreateDoubleScalar(-10); return; } plhs[0] = mxCreateDoubleScalar(nRangeElements); }
int main(int argc, char *argv[]) { fd_set rfds; int opt; int inotifyFd; /* Parse command-line options */ verboseMask = 0; checkCache = 0; dumpCache = 0; stopFile = NULL; abortOnCacheProblem = 0; while ((opt = getopt(argc, argv, "a:dxl:v:b:")) != -1) { switch (opt) { case 'a': abortOnCacheProblem = 1; stopFile = optarg; break; case 'x': checkCache = 1; break; case 'd': dumpCache = 1; break; case 'v': verboseMask = atoi(optarg); break; case 'b': readBufferSize = atoi(optarg); break; case 'l': logfp = fopen(optarg, "w+"); if (logfp == NULL) errExit("fopen"); setbuf(logfp, NULL); break; default: usageError(argv[0]); } } if (optind >= argc) usageError(argv[0]); /* Save a copy of the directories on the command line */ copyRootDirPaths(&argv[optind]); /* Create an inotify instance and populate it with entries for directory named on command line */ inotifyFd = reinitialize(-1); /* Loop to handle inotify events and keyboard commands */ printf("%s> ", argv[0]); fflush(stdout); for (;;) { FD_ZERO(&rfds); FD_SET(STDIN_FILENO, &rfds); FD_SET(inotifyFd, &rfds); if (select(inotifyFd + 1, &rfds, NULL, NULL, NULL) == -1) errExit("select"); if (FD_ISSET(STDIN_FILENO, &rfds)) { executeCommand(&inotifyFd); printf("%s> ", argv[0]); fflush(stdout); } if (FD_ISSET(inotifyFd, &rfds)) processInotifyEvents(&inotifyFd); } exit(EXIT_SUCCESS); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // drawing parameters size_t primitiveIndex = 0; GLenum primitive = GL_POINTS; GLsizei nVertices = 0; GLint offsetVertices = 0; GLfloat size = 1; // VBO data for indexed drawing GLuint bufferID = 0; size_t bytesPerElement = 0; size_t byteOffset = 0; mxArray* mxData = NULL; GLenum glType = GL_UNSIGNED_INT; // status int status = 0; GLenum error = GL_NO_ERROR; dotsMglClearGLErrors(); // check input arguments if (nrhs < 2 || nrhs > 5 || !mxIsNumeric(prhs[0]) || mxIsEmpty(prhs[0]) || !mxIsNumeric(prhs[1]) || mxIsEmpty(prhs[1])) { plhs[0] = mxCreateDoubleScalar(-1); usageError("dotsMglDrawVertices"); return; } // choose the primitive drawing type primitiveIndex = (size_t)mxGetScalar(prhs[0]); if (primitiveIndex >= 0 && primitiveIndex < NUM_GL_PRIMITIVES) { primitive = GL_PRIMITIVES[primitiveIndex]; } else { mexPrintf("(dotsMglDrawVertices) Primitive index %d is out of defined range %d - %d.\n", primitiveIndex, 0, NUM_GL_PRIMITIVES-1); plhs[0] = mxCreateDoubleScalar(-2); return; } // choose how many vertices to draw // client state should be enabled and disabled with // dotsMglSelectVertexData and dotsMglSelectVertexAttributes nVertices = (GLsizei)mxGetScalar(prhs[1]); // choose the range offset, if supplied. Expect 0-based offset if (nrhs >= 3 && mxIsNumeric(prhs[2]) && !mxIsEmpty(prhs[2])) offsetVertices = (size_t)mxGetScalar(prhs[2]); // choose the point or line size, if supplied if (nrhs >= 4 && mxIsNumeric(prhs[3]) && !mxIsEmpty(prhs[3])) { size = (GLfloat)mxGetScalar(prhs[3]); if (primitiveIndex == 0) { glPointSize(size); } else if (primitiveIndex <= 3) { glLineWidth(size); } } // draw vertices with previously chosen data glEnableClientState(GL_VERTEX_ARRAY); if (nrhs >= 5 && mxIsStruct(prhs[4]) && !mxIsEmpty(prhs[4])) { // draw specific elements of the enabled arrays // VBO accounting bufferID = (GLuint)dotsMglGetInfoScalar(prhs[4], 0, "bufferID", &status); if (status < 0) { mexPrintf("(dotsMglSelectVertexData) index buffer info struct is invalid.\n"); plhs[0] = mxCreateDoubleScalar(-3); return; } bytesPerElement = (size_t)dotsMglGetInfoScalar(prhs[4], 0, "bytesPerElement", &status); byteOffset = offsetVertices * bytesPerElement; mxData = mxGetField(prhs[4], 0, "mxData"); glType = dotsMglGetGLNumericType(mxData); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferID); glDrawElements(primitive, nVertices, glType, BUFFER_OFFSET(byteOffset)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } else { // draw enabled arrays sequentially glDrawArrays(primitive, offsetVertices, nVertices); } error = glGetError(); if(error != GL_NO_ERROR) { mexPrintf("(dotsMglDrawVertices) Error drawing vertices. glGetError()=%d\n", error); plhs[0] = mxCreateDoubleScalar(-10); return; } // success! plhs[0] = mxCreateDoubleScalar(nVertices); }
int main(int argc, char *argv[]) { struct sigaction sa; int fd, events, fnum; const int NOTIFY_SIG = SIGRTMIN; char *p; if (argc < 2 || strcmp(argv[1], "--help") == 0) usageError(argv[0], NULL); /* Establish handler for notification signal */ sa.sa_sigaction = handler; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_SIGINFO; /* So handler gets siginfo_t arg. */ if (sigaction(NOTIFY_SIG, &sa, NULL) == -1) errExit("sigaction"); for (fnum = 1; fnum < argc; fnum++) { p = strchr(argv[fnum], ':'); /* Look for optional ':' */ if (p == NULL) { /* Default is all events + multishot */ events = DN_ACCESS | DN_ATTRIB | DN_CREATE | DN_DELETE | DN_MODIFY | DN_RENAME | DN_MULTISHOT; } else { /* ':' present, parse event chars */ *p = '\0'; /* Terminates directory component */ events = 0; for (p++; *p != '\0'; p++) { switch (*p) { case 'a': events |= DN_ACCESS; break; case 'A': events |= DN_ATTRIB; break; case 'c': events |= DN_CREATE; break; case 'd': events |= DN_DELETE; break; case 'm': events |= DN_MODIFY; break; case 'r': events |= DN_RENAME; break; case 'M': events |= DN_MULTISHOT; break; default: usageError(argv[0], "Bad event character\n"); } } } /* Obtain a file descriptor for the directory to be monitored */ fd = open(argv[fnum], O_RDONLY); if (fd == -1) errExit("open"); printf("opened '%s' as file descriptor %d\n", argv[fnum], fd); /* Use alternate signal instead of SIGIO for dnotify events */ if (fcntl(fd, F_SETSIG, NOTIFY_SIG) == -1) errExit("fcntl - F_SETSIG"); /* Enable directory change notifications */ if (fcntl(fd, F_NOTIFY, events) == -1) errExit("fcntl-F_NOTIFY"); printf("events: %o\n", (unsigned int) events); } for (;;) pause(); /* Wait for events */ }