static int set_score_adj(const pid_t pid, int adj) { char buf[sizeof(stringify_value(INT_MAX))]; snprintf(buf, sizeof(buf), "%d", adj); if (path_write_str(buf, "/proc/%d/oom_score_adj", (int) pid) < 0) return -1; return 0; }
int sysfs_write_u64(struct sysfs_cxt *cxt, const char *attr, uint64_t num) { char buf[sizeof(stringify_value(ULLONG_MAX))]; int fd, rc = 0, len, errsv; fd = sysfs_open(cxt, attr, O_WRONLY|O_CLOEXEC); if (fd < 0) return -errno; len = snprintf(buf, sizeof(buf), "%ju", num); if (len < 0 || (size_t) len + 1 > sizeof(buf)) rc = -errno; else rc = write_all(fd, buf, len); errsv = errno; close(fd); errno = errsv; return rc; }
/* void play_card(player p, int i) { //check if this is a valid next card to play if ( p.cards[i].color == top_card.color || p.cards[i].value == top_card.value ) { //remove card from p.cards and update num_cards p.num_cards--; remove_card( p, i ); update_top_card( ); //**[DONE]**change the card that is on top of the pile (shared memory?) } else { //ask player for another card to play printf( "Invalid card \n" ); //play_card(p, newcard); } } */ void player_action(player p) { //print out options for the player printf("It's your turn! What would you like to do?\n"); printf("Options:\n"); int i; //printf("p.num_cards: %d\n", p.num_cards); for ( i = 0; i < p.num_cards; i++ ) { //if ( p.cards[i].color == 0 ) printf("%d - Play %s %s\n", i, stringify_color(p.cards[i]), stringify_value(p.cards[i])); } printf("%d - Draw a card\n", i++); /* //get player input as an int int input; scanf("%d", &input); //action if (input < p.num_cards && input >= 0) { //player wanted to play a card //code to remove card from hand, update top_card, update num_cards play_card( p, input ); } else if (input == p.num_cards) { //player wants to draw a card //code to draw a card and update num_cards p.cards[p.num_cards] = draw_card(); p.num_cards++; //skip, reverse, +2, wild, wild +4 } else { //player entered an invalid input //ask player to input a valid input print( "Invalid input\n"); } //next_player(); */ }
char * stringify_card (card c){ char * ret = strcat(stringify_value(c),stringify_color(c)); return ret; }