Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <nspire.h>
  4.  
  5. struct nsp_ctx {
  6.     nspire_handle_t *handle;
  7. };
  8.  
  9. int main(int argc, char *argv[] )
  10. {
  11.     int ret = 0;
  12.     struct nsp_ctx *ctx = malloc(sizeof(*ctx));
  13.  
  14.     if (argc != 3) {
  15.         printf( "usage: %s local-source-path remote-destination-path\r\n", argv[0]);
  16.     }
  17.  
  18.     else if ((ret = nspire_init(&ctx->handle))) {
  19.         printf("Couldn't init handle, error: %d\r\n", ret);
  20.     }
  21.  
  22.     else {
  23.         FILE *f = fopen(argv[1], "rb");
  24.  
  25.         fseek(f, 0, SEEK_END);
  26.         long fsize = ftell(f);
  27.         fseek(f, 0, SEEK_SET);
  28.  
  29.         char *data = malloc(fsize);
  30.         size_t bsize = fread(data, fsize, 1, f);
  31.         fclose(f);
  32.  
  33.         nspire_file_write(ctx->handle, argv[2], data, bsize);
  34.         nspire_free(ctx->handle);
  35.     }
  36.  
  37.     free(ctx);
  38.  
  39.     return ret;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement