| OLD | NEW |
| 1 // Copyright (c) 2006, Google Inc. | 1 // Copyright (c) 2006, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 |
| 30 // file_id.cc: Return a unique identifier for a file | 30 // file_id.cc: Return a unique identifier for a file |
| 31 // | 31 // |
| 32 // See file_id.h for documentation | 32 // See file_id.h for documentation |
| 33 // | 33 // |
| 34 // Author: Dan Waylonis | 34 // Author: Dan Waylonis |
| 35 | 35 |
| 36 #include <fcntl.h> | 36 #include <fcntl.h> |
| 37 #include <stdio.h> |
| 37 #include <string.h> | 38 #include <string.h> |
| 38 #include <unistd.h> | 39 #include <unistd.h> |
| 39 | 40 |
| 40 #include "common/mac/file_id.h" | 41 #include "common/mac/file_id.h" |
| 41 #include "common/mac/macho_id.h" | 42 #include "common/mac/macho_id.h" |
| 42 | 43 |
| 43 using MacFileUtilities::MachoID; | 44 using MacFileUtilities::MachoID; |
| 44 | 45 |
| 45 namespace google_breakpad { | 46 namespace google_breakpad { |
| 46 | 47 |
| 47 FileID::FileID(const char *path) { | 48 FileID::FileID(const char *path) { |
| 48 strlcpy(path_, path, sizeof(path_)); | 49 snprintf(path_, sizeof(path_), "%s", path); |
| 49 } | 50 } |
| 50 | 51 |
| 51 bool FileID::FileIdentifier(unsigned char identifier[16]) { | 52 bool FileID::FileIdentifier(unsigned char identifier[16]) { |
| 52 int fd = open(path_, O_RDONLY); | 53 int fd = open(path_, O_RDONLY); |
| 53 if (fd == -1) | 54 if (fd == -1) |
| 54 return false; | 55 return false; |
| 55 | 56 |
| 56 MD5Context md5; | 57 MD5Context md5; |
| 57 MD5Init(&md5); | 58 MD5Init(&md5); |
| 58 | 59 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 static_cast<char>((hi >= 10) ? ('A' + hi - 10) : ('0' + hi)); | 97 static_cast<char>((hi >= 10) ? ('A' + hi - 10) : ('0' + hi)); |
| 97 buffer[buffer_idx++] = | 98 buffer[buffer_idx++] = |
| 98 static_cast<char>((lo >= 10) ? ('A' + lo - 10) : ('0' + lo)); | 99 static_cast<char>((lo >= 10) ? ('A' + lo - 10) : ('0' + lo)); |
| 99 } | 100 } |
| 100 | 101 |
| 101 // NULL terminate | 102 // NULL terminate |
| 102 buffer[(buffer_idx < buffer_length) ? buffer_idx : buffer_idx - 1] = 0; | 103 buffer[(buffer_idx < buffer_length) ? buffer_idx : buffer_idx - 1] = 0; |
| 103 } | 104 } |
| 104 | 105 |
| 105 } // namespace google_breakpad | 106 } // namespace google_breakpad |
| OLD | NEW |