- /**
- * 文件md5值转换工具
- * filename:待转换文件
- * result:返回转换成md5后的值
- */
- int get_file_to_md5(char* filename, char* result) {
- FILE *fstream = NULL;
- char buff[1024];
- memset(buff, 0, sizeof(buff));
- char path[100] = "md5sum ";
- strcat(path, filename);
- if (NULL == (fstream = popen(path, "r"))) {
- return -1;
- }
- if (NULL != fgets(buff, sizeof(buff), fstream)) {
- strcpy(result, strtok(buff, " "));
- } else {
- pclose(fstream);
- return -1;
- }
- pclose(fstream);
- return code_ok;
- }
- //该片段来自于http://www.codesnippet.cn/detail/110220148677.html
来源: http://www.codesnippet.cn/detail/110220148677.html