@@ -68,6 +68,26 @@ C-SDK 使用 [cURL](http://curl.haxx.se/) 进行网络相关操作。无论是
68
68
69
69
如果在项目构建过程中出现环境相关的编译错误和链接错误,请确认这些选项是否都已经正确配置,以及所依赖的库是否都已经正确的安装。
70
70
71
+ #### 通过 CMake 编译
72
+
73
+ 如果想在 CMake 项目里使用 C-SDK,可以直接在 CMake 里导入 C-SDK:
74
+
75
+ ``` cmake
76
+ INCLUDE(FetchContent)
77
+ FetchContent_Declare(
78
+ qiniu
79
+ GIT_REPOSITORY https://github.com/qiniu/c-sdk.git
80
+ GIT_TAG v7.7.0
81
+ )
82
+ FetchContent_MakeAvailable(qiniu)
83
+
84
+ FIND_PACKAGE(CURL REQUIRED)
85
+ FIND_PACKAGE(OpenSSL REQUIRED)
86
+
87
+ TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE qiniu m)
88
+ TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE ${CURL_LIBRARIES})
89
+ TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE ${OPENSSL_LIBRARIES})
90
+ ```
71
91
72
92
<a name =" appkey " ></a >
73
93
@@ -146,7 +166,7 @@ void stat(Qiniu_Client* client, const char* bucket, const char* key)
146
166
{
147
167
Qiniu_RS_StatRet ret;
148
168
Qiniu_Error err = Qiniu_RS_Stat(client, &ret, bucket, key);
149
- if (err.code != 200 ) {
169
+ if (err.code != Qiniu_OK.code ) {
150
170
debug(client, err);
151
171
return;
152
172
}
@@ -169,7 +189,7 @@ typedef struct _Qiniu_Error {
169
189
typedef struct _Qiniu_RS_StatRet {
170
190
const char* hash;
171
191
const char* mimeType;
172
- Qiniu_Int64 fsize;
192
+ Qiniu_Int64 fsize;
173
193
Qiniu_Int64 putTime;
174
194
} Qiniu_RS_StatRet;
175
195
```
@@ -259,7 +279,7 @@ char* upload(Qiniu_Client* client, char* uptoken, const char* key, const char* l
259
279
Qiniu_Error err;
260
280
Qiniu_Io_PutRet putRet;
261
281
err = Qiniu_Io_PutFile(client, &putRet, uptoken, key, localFile, NULL);
262
- if (err.code != 200 ) {
282
+ if (err.code != Qiniu_OK.code ) {
263
283
debug(client, err);
264
284
return NULL;
265
285
}
@@ -413,7 +433,7 @@ void stat(Qiniu_Client* client, const char* bucket, const char* key)
413
433
{
414
434
Qiniu_RS_StatRet ret;
415
435
Qiniu_Error err = Qiniu_RS_Stat(client, &ret, bucket, key);
416
- if (err.code != 200 ) {
436
+ if (err.code != Qiniu_OK.code ) {
417
437
debug(client, err);
418
438
return;
419
439
}
@@ -427,7 +447,7 @@ void stat(Qiniu_Client* client, const char* bucket, const char* key)
427
447
typedef struct _Qiniu_RS_StatRet {
428
448
const char* hash;
429
449
const char* mimeType;
430
- Qiniu_Int64 fsize;
450
+ Qiniu_Int64 fsize;
431
451
Qiniu_Int64 putTime;
432
452
} Qiniu_RS_StatRet;
433
453
```
@@ -442,7 +462,7 @@ typedef struct _Qiniu_RS_StatRet {
442
462
void delete(Qiniu_Client* client, const char* bucket, const char* key)
443
463
{
444
464
Qiniu_Error err = Qiniu_RS_Delete(client, bucket, key);
445
- if (err.code != 200 ) {
465
+ if (err.code != Qiniu_OK.code ) {
446
466
debug(client, err);
447
467
return;
448
468
}
@@ -456,12 +476,12 @@ void delete(Qiniu_Client* client, const char* bucket, const char* key)
456
476
复制和移动操作,需要指定源路径和目标路径。
457
477
458
478
``` {c}
459
- void copy(Qiniu_Client* client,
460
- const char* bucketSrc, const char* keySrc,
479
+ void copy(Qiniu_Client* client,
480
+ const char* bucketSrc, const char* keySrc,
461
481
const char* bucketDest, const char* keyDest)
462
482
{
463
483
Qiniu_Error err = Qiniu_RS_Copy(client, bucketSrc, keySrc, bucketDest, keyDest);
464
- if (err.code != 200 ) {
484
+ if (err.code != Qiniu_OK.code ) {
465
485
debug(client, err);
466
486
return;
467
487
}
@@ -470,12 +490,12 @@ void copy(Qiniu_Client* client,
470
490
```
471
491
472
492
``` {c}
473
- void move(Qiniu_Client* client,
474
- const char* bucketSrc, const char* keySrc,
493
+ void move(Qiniu_Client* client,
494
+ const char* bucketSrc, const char* keySrc,
475
495
const char* bucketDest, const char* keyDest)
476
496
{
477
497
Qiniu_Error err = Qiniu_RS_Move(client, bucketSrc, keySrc, bucketDest, keyDest);
478
- if (err.code != 200 ) {
498
+ if (err.code != Qiniu_OK.code ) {
479
499
debug(client, err);
480
500
return;
481
501
}
@@ -494,7 +514,7 @@ void move(Qiniu_Client* client,
494
514
调用` Qiniu_RS_BatchStat ` 可以批量查看多个文件的属性信息。
495
515
496
516
``` {c}
497
- void batchStat(Qiniu_Client* client,
517
+ void batchStat(Qiniu_Client* client,
498
518
Qiniu_RS_EntryPath* entries, Qiniu_ItemCount entryCount)
499
519
{
500
520
Qiniu_RS_BatchStatRet* rets = calloc(entryCount, sizeof(Qiniu_RS_BatchStatRet));
@@ -504,7 +524,7 @@ void batchStat(Qiniu_Client* client,
504
524
while (curr < entryCount) {
505
525
printf("\ncode: %d\n", rets[curr].code);
506
526
507
- if (rets[curr].code != 200 ) {
527
+ if (rets[curr].code != Qiniu_OK.code ) {
508
528
printf("error: %s\n", rets[curr].error);
509
529
} else {
510
530
printf("hash: %s\n", rets[curr].data.hash);
@@ -517,7 +537,7 @@ void batchStat(Qiniu_Client* client,
517
537
518
538
free(rets);
519
539
520
- if (err.code != 200 ) {
540
+ if (err.code != Qiniu_OK.code ) {
521
541
debug(client, err);
522
542
return;
523
543
}
@@ -551,7 +571,7 @@ typedef struct _Qiniu_RS_BatchStatRet {
551
571
typedef struct _Qiniu_RS_StatRet {
552
572
const char* hash;
553
573
const char* mimeType;
554
- Qiniu_Int64 fsize;
574
+ Qiniu_Int64 fsize;
555
575
Qiniu_Int64 putTime;
556
576
} Qiniu_RS_StatRet;
557
577
```
@@ -563,7 +583,7 @@ typedef struct _Qiniu_RS_StatRet {
563
583
调用` Qiniu_RS_BatchDelete ` 可以批量删除多个文件。
564
584
565
585
``` {c}
566
- void batchDelete(Qiniu_Client* client,
586
+ void batchDelete(Qiniu_Client* client,
567
587
Qiniu_RS_EntryPath* entries, Qiniu_ItemCount entryCount)
568
588
{
569
589
Qiniu_RS_BatchItemRet* rets = calloc(entryCount, sizeof(Qiniu_RS_BatchItemRet));
@@ -573,15 +593,15 @@ void batchDelete(Qiniu_Client* client,
573
593
while (curr < entryCount) {
574
594
printf("\ncode: %d\n", rets[curr].code);
575
595
576
- if (rets[curr].code != 200 ) {
596
+ if (rets[curr].code != Qiniu_OK.code ) {
577
597
printf("error: %s\n", rets[curr].error);
578
598
}
579
599
curr++;
580
600
}
581
601
582
602
free(rets);
583
603
584
- if (err.code != 200 ) {
604
+ if (err.code != Qiniu_OK.code ) {
585
605
debug(client, err);
586
606
return;
587
607
}
@@ -604,7 +624,7 @@ typedef struct _Qiniu_RS_BatchItemRet {
604
624
调用` Qiniu_RS_BatchCopy ` 可以批量复制多个文件。
605
625
606
626
``` {c}
607
- void batchCopy(Qiniu_Client* client,
627
+ void batchCopy(Qiniu_Client* client,
608
628
Qiniu_RS_EntryPathPair* entryPairs, Qiniu_ItemCount entryCount)
609
629
{
610
630
Qiniu_RS_BatchItemRet* rets = calloc(entryCount, sizeof(Qiniu_RS_BatchItemRet));
@@ -614,14 +634,14 @@ void batchCopy(Qiniu_Client* client,
614
634
while (curr < entryCount) {
615
635
printf("\ncode: %d\n", rets[curr].code);
616
636
617
- if (rets[curr].code != 200 ) {
637
+ if (rets[curr].code != Qiniu_OK.code ) {
618
638
printf("error: %s\n", rets[curr].error);
619
639
}
620
640
curr++;
621
641
}
622
642
free(rets);
623
643
624
- if (err.code != 200 ) {
644
+ if (err.code != Qiniu_OK.code ) {
625
645
debug(client, err);
626
646
return;
627
647
}
@@ -644,7 +664,7 @@ typedef struct _Qiniu_RS_EntryPathPair {
644
664
批量移动和批量复制很类似,唯一的区别就是调用` Qiniu_RS_BatchMove ` 。
645
665
646
666
``` {c}
647
- void batchMove(Qiniu_Client* client,
667
+ void batchMove(Qiniu_Client* client,
648
668
Qiniu_RS_EntryPathPair* entryPairs, Qiniu_ItemCount entryCount)
649
669
{
650
670
Qiniu_RS_BatchItemRet* rets = calloc(entryCount, sizeof(Qiniu_RS_BatchItemRet));
@@ -654,15 +674,15 @@ void batchMove(Qiniu_Client* client,
654
674
while (curr < entryCount) {
655
675
printf("\ncode: %d\n", rets[curr].code);
656
676
657
- if (rets[curr].code != 200 ) {
677
+ if (rets[curr].code != Qiniu_OK.code ) {
658
678
printf("error: %s\n", rets[curr].error);
659
679
}
660
680
curr++;
661
681
}
662
682
663
683
free(rets);
664
684
665
- if (err.code != 200 ) {
685
+ if (err.code != Qiniu_OK.code ) {
666
686
debug(client, err);
667
687
return;
668
688
}
0 commit comments