SNFCoreAudioUtils.c 779 B

1234567891011121314151617181920212223242526272829
  1. //
  2. // SNFCoreAudioUtils.c
  3. // VTMAUGraphDemo
  4. //
  5. // Created by Chris Adamson on 11/8/11.
  6. // Copyright (c) 2011 Subsequently and Furthermore, Inc. All rights reserved.
  7. //
  8. #include <stdio.h>
  9. #include "SNFCoreAudioUtils.h"
  10. // generic error handler - if err is nonzero, prints error message and exits program.
  11. void CheckError(OSStatus error, const char *operation) {
  12. if (error == noErr) return;
  13. char str[20];
  14. // see if it appears to be a 4-char-code
  15. *(UInt32 *)(str + 1) = CFSwapInt32HostToBig(error);
  16. if (isprint(str[1]) && isprint(str[2]) && isprint(str[3]) && isprint(str[4])) {
  17. str[0] = str[5] = '\'';
  18. str[6] = '\0';
  19. } else
  20. // no, format it as an integer
  21. sprintf(str, "%d", (int)error);
  22. fprintf(stderr, "Error: %s (%s)\n", operation, str);
  23. //exit(1);
  24. }