fork(2) download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. int check_bytes(const char * const data, size_t length, const char val)
  6. {
  7. if(length == 0) return 1;
  8. if(*data != val) return 0;
  9. return memcmp(data, data+1, length-1) ? 0 : 1;
  10. }
  11.  
  12. int main(void) {
  13. const size_t LEN = 12345;
  14. char * data0 = calloc(1, LEN);
  15. char * data1 = calloc(1, LEN);
  16. data1[1234] = 5;
  17.  
  18. printf("Data 0 should be all-0: %s\n", check_bytes(data0, LEN, 0) ? "yes": "no");
  19. printf("Data 1 should NOT be all-0: %s\n", check_bytes(data1, LEN, 0) ? "yes": "no");
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 2304KB
stdin
Standard input is empty
stdout
Data 0 should be all-0: yes
Data 1 should NOT be all-0: no