void receive(void *arg) { int done = 0; int cl_sock = (int) arg; char buffer[MAX_BUFFER]; int argc; char *argv[5]; int i; while (!done) { recv (cl_sock, buffer, sizeof(buffer), 0); i = 0; while (buffer[i++]!=';') {} buffer[i]='\0'; printf("Received message: '%s'\n", buffer); parse (buffer, argv, &argc); if ( !strcmp(argv[0], "LOGIN") ) { if (argc < 4) printf("Wrong number of arguments (%d).\n",argc); else add_login (argv[1], argv[2], (int)(atoi(argv[3]))); } else if ( !strcmp(argv[0], "LOGOUT") ) { if (argc < 4) { printf("Wrong number of arguments (%d).\n",argc); close(cl_sock); printf("Thread exiting with error.\n"); pthread_exit(NULL); } else { del_login (argv[1], argv[2], (int)(atoi(argv[3]))); done = 1; } } else if ( !strcmp(argv[0], "HEY") ) { if (argc < 1) printf("Wrong number of arguments (%d).\n",argc); else get_logins(cl_sock); } else { printf("Unrecognized command.\n"); } } close(cl_sock); printf("Thread exiting.\n"); pthread_exit(NULL); }
void get_long(t_blk *blk) { get_logins(blk); ENTRY(blk)->len[0] = get_nbr_len(ENTRY(blk)->stat.st_nlink); if (S_ISCHR(ENTRY(blk)->stat.st_mode) || S_ISBLK(ENTRY(blk)->stat.st_mode)) { ENTRY(blk)->len[3] = get_nbr_len(MAJOR(ENTRY(blk)->stat.st_rdev)); ENTRY(blk)->len[4] = get_nbr_len(MINOR(ENTRY(blk)->stat.st_rdev)); } else ENTRY(blk)->len[3] = get_nbr_len(ENTRY(blk)->stat.st_size); ENTRY(blk)->len[5] = ENTRY(blk)->stat.st_blocks; }