Class: SMB::File

Inherits:
Object
  • Object
show all
Defined in:
ext/smb/smb.c

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObject



993
994
995
996
997
998
999
1000
1001
# File 'ext/smb/smb.c', line 993

static VALUE
File_initialize(VALUE self)
{
rb_smbprivate *file; Data_Get_Struct(self, rb_smbprivate, file);

#line 312 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
  
  return Qnil;
}

Class Method Details

.create(__v_url, __v_mode) ⇒ Object



918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
# File 'ext/smb/smb.c', line 918

static VALUE
File_CLASS_create(VALUE self, VALUE __v_url, VALUE __v_mode)
{
  VALUE __p_retval = Qnil;
  char * url; char * __orig_url;
  int mode; int __orig_mode;
  __orig_url = url = ( NIL_P(__v_url) ? NULL : StringValuePtr(__v_url) );
  __orig_mode = mode = NUM2INT(__v_mode);

#line 277 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"

  do {
  volatile VALUE  val  ;
 struct rb_smbprivate * file  ;
 int  handle  =
 0;
  if ((handle = smbc_creat(url, mode)) < 0) { rb_sys_fail(url);
  } val = Data_Make_Struct(self, struct rb_smbprivate, 0, smbprivate_free, file);
  file->handle = handle;
  file->url = strdup(url);
  rb_obj_call_init(val, 0, NULL);
  do { __p_retval = val; goto out; } while(0);

  } while(0);

out:
  return __p_retval;
}

.new(__v_url, __v_flags, __v_mode) ⇒ Object



887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
# File 'ext/smb/smb.c', line 887

static VALUE
File_CLASS_new(VALUE self, VALUE __v_url, VALUE __v_flags, VALUE __v_mode)
{
  VALUE __p_retval = Qnil;
  char * url; char * __orig_url;
  int flags; int __orig_flags;
  int mode; int __orig_mode;
  __orig_url = url = ( NIL_P(__v_url) ? NULL : StringValuePtr(__v_url) );
  __orig_flags = flags = NUM2INT(__v_flags);
  __orig_mode = mode = NUM2INT(__v_mode);

#line 259 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"

  do {
  volatile VALUE  val  ;
 struct rb_smbprivate * file  ;
 int  handle  =
 0;
  if ((handle = smbc_open(url, flags, mode)) < 0) { rb_sys_fail(url);
  } val = Data_Make_Struct(self, struct rb_smbprivate, 0, smbprivate_free, file);
  file->handle = handle;
  file->url = strdup(url);
  rb_obj_call_init(val, 0, NULL);
  do { __p_retval = val; goto out; } while(0);

  } while(0);

out:
  return __p_retval;
}

.read(__v_url) ⇒ Object



1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
# File 'ext/smb/smb.c', line 1130

static VALUE
File_CLASS_read(VALUE self, VALUE __v_url)
{
  VALUE __p_retval = Qnil;
  char * url; char * __orig_url;
  __orig_url = url = ( NIL_P(__v_url) ? NULL : StringValuePtr(__v_url) );

#line 376 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"

  do {
  size_t  read  ;
 struct stat  s  ;
 char  buf [4096] ;
 volatile VALUE  str  ;
 int next_read = 0, handle, bytes_to_read;
  if ((handle = smbc_open(url, O_RDONLY, 0)) < 0) rb_sys_fail(url);
  if (smbc_fstat(handle, &s) < 0) rb_sys_fail(url);
  bytes_to_read = s.st_size;
  if(bytes_to_read > sizeof(buf)) next_read = sizeof(buf);
  else next_read = bytes_to_read;
  str = rb_str_new("",0);
  while((read = smbc_read(handle, buf, next_read))!=0) { rb_str_cat(str, buf, read);
  bytes_to_read -= read;
  if(bytes_to_read == 0) break;
  if(bytes_to_read > sizeof(buf)) next_read = sizeof(buf);
  else next_read = bytes_to_read;
  } smbc_close(handle);
  do { __p_retval = str; goto out; } while(0);

  } while(0);

out:
  return __p_retval;
}

.rename(__v_ourl, __v_nurl) ⇒ Object



959
960
961
962
963
964
965
966
967
968
969
970
971
# File 'ext/smb/smb.c', line 959

static VALUE
File_CLASS_rename(VALUE self, VALUE __v_ourl, VALUE __v_nurl)
{
  char * ourl; char * __orig_ourl;
  char * nurl; char * __orig_nurl;
  __orig_ourl = ourl = ( NIL_P(__v_ourl) ? NULL : StringValuePtr(__v_ourl) );
  __orig_nurl = nurl = ( NIL_P(__v_nurl) ? NULL : StringValuePtr(__v_nurl) );

#line 299 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
  if (smbc_rename(ourl, nurl) < 0) rb_sys_fail(ourl);
 
  return Qnil;
}

.stat(__v_url) ⇒ Object



973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
# File 'ext/smb/smb.c', line 973

static VALUE
File_CLASS_stat(VALUE self, VALUE __v_url)
{
  VALUE __p_retval = Qnil;
  char * url; char * __orig_url;
  __orig_url = url = ( NIL_P(__v_url) ? NULL : StringValuePtr(__v_url) );

#line 303 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"

  do {
  struct stat  s  ;
 if (smbc_stat(url, &s) < 0) rb_sys_fail(url);
  do { __p_retval = stat_new(&s); goto out; } while(0);

  } while(0);

out:
  return __p_retval;
}


947
948
949
950
951
952
953
954
955
956
957
# File 'ext/smb/smb.c', line 947

static VALUE
File_CLASS_unlink(VALUE self, VALUE __v_url)
{
  char * url; char * __orig_url;
  __orig_url = url = ( NIL_P(__v_url) ? NULL : StringValuePtr(__v_url) );

#line 295 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
  if (smbc_unlink(url) < 0) rb_sys_fail(url);
 
  return Qnil;
}

Instance Method Details

#closeObject



1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
# File 'ext/smb/smb.c', line 1118

static VALUE
File_close(VALUE self)
{
rb_smbprivate *file; Data_Get_Struct(self, rb_smbprivate, file);

#line 371 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
  smbc_close(file->handle);
  file->handle = 0;
 
  return Qnil;
}

#read(*__p_argv, self) ⇒ Object



1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
# File 'ext/smb/smb.c', line 1051

static VALUE
File_read(int __p_argc, VALUE *__p_argv, VALUE self)
{
  VALUE __p_retval = Qnil;
  VALUE __v_bytes_to_read = Qnil;
  int bytes_to_read; int __orig_bytes_to_read;
rb_smbprivate *file; Data_Get_Struct(self, rb_smbprivate, file);

  /* Scan arguments */
  rb_scan_args(__p_argc, __p_argv, "01",&__v_bytes_to_read);

  /* Set defaults */
  if (__p_argc > 0)
    __orig_bytes_to_read = bytes_to_read = NUM2INT(__v_bytes_to_read);
  else
    bytes_to_read = -1;


#line 326 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"

  do {
  size_t  read  ;
 struct stat  s  ;
 char  buf [4096] ;
 volatile VALUE  str  =
 Qnil;
  int next_read = 0;
  if(bytes_to_read == -1) { if (smbc_fstat(file->handle, &s) < 0) rb_sys_fail(file->url);
  bytes_to_read = s.st_size;
  } if(bytes_to_read > sizeof(buf)) next_read = sizeof(buf);
  else next_read = bytes_to_read;
  while((read = smbc_read(file->handle, buf, next_read))!=0) { if(str == Qnil) str = rb_str_new("",0);
  rb_str_cat(str, buf, read);
  bytes_to_read -= read;
  if(bytes_to_read == 0) break;
  if(bytes_to_read > sizeof(buf)) next_read = sizeof(buf);
  else next_read = bytes_to_read;
  } do { __p_retval = str; goto out; } while(0);

  } while(0);

out:
  return __p_retval;
}

#seek(__v_offset, __v_whence) ⇒ Object



1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
# File 'ext/smb/smb.c', line 1034

static VALUE
File_seek(VALUE self, VALUE __v_offset, VALUE __v_whence)
{
  VALUE __p_retval = Qnil;
  off_t offset; off_t __orig_offset;
  int whence; int __orig_whence;
rb_smbprivate *file; Data_Get_Struct(self, rb_smbprivate, file);
  __orig_offset = offset = NUM2OFFT(__v_offset);
  __orig_whence = whence = NUM2INT(__v_whence);

#line 323 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
  do { __p_retval = INT2NUM(smbc_lseek(file->handle, offset, whence)); goto out; } while(0);
out:
;
  return __p_retval;
}

#statObject



1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
# File 'ext/smb/smb.c', line 1003

static VALUE
File_stat(VALUE self)
{
  VALUE __p_retval = Qnil;
rb_smbprivate *file; Data_Get_Struct(self, rb_smbprivate, file);

#line 314 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"

  do {
  struct stat  s  ;
 if (smbc_fstat(file->handle, &s) < 0) rb_sys_fail(file->url);
  do { __p_retval = stat_new(&s); goto out; } while(0);

  } while(0);

out:
  return __p_retval;
}

#urlObject



1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
# File 'ext/smb/smb.c', line 1022

static VALUE
File_url(VALUE self)
{
  VALUE __p_retval = Qnil;
rb_smbprivate *file; Data_Get_Struct(self, rb_smbprivate, file);

#line 320 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
  do { __p_retval =  rb_str_new2(file->url); goto out; } while(0);
out:
  return __p_retval;
}

#write(buf) ⇒ Object



1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
# File 'ext/smb/smb.c', line 1096

static VALUE
File_write(VALUE self, VALUE buf)
{
  VALUE __p_retval = Qnil;
rb_smbprivate *file; Data_Get_Struct(self, rb_smbprivate, file);
  Check_Type(buf, T_STRING);

#line 363 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"

  do {
  int  i  ;
 StringValue(buf);
  i = smbc_write(file->handle, RSTRING_PTR(buf), RSTRING_LEN(buf));
  if (i < 0) rb_sys_fail("write");
  do { __p_retval =  LONG2NUM(i); goto out; } while(0);

  } while(0);

out:
  return __p_retval;
}