/* chgccsid.c ... change codepage of file */ /* author jack j. woehr jax@softwoehr.com */ /* FREE SOFTWARE NO WARRANTY NO GUARANTEE */ /* 2000-10-11 Thanx to Karl Hanson of IBM */ #include #include #include #include #include #define MIN(x,y) ((x < y ? x : y)) void usage (char *argv[]) { printf("Usage: %s ifspath codepage\n", argv[0]); printf("Assumes US ENU CCSID 37 for path names. Fix it yourself!\n"); } typedef struct t_chg_cod_pag { Qp0l_Attr_Header_t attr_hdr; int code_page; } chg_cod_pag_t; typedef struct t_path_name { Qlg_Path_Name_T qlg_path_name; char ifs_path [FILENAME_MAX]; } path_name_t; int chgcodepage(char * path, int cpage) { int result = 0; chg_cod_pag_t chg_cod_pag; path_name_t path_name; chg_cod_pag.attr_hdr.Next_Attr_Offset = 0; chg_cod_pag.attr_hdr.Attr_ID = QP0L_ATTR_CODEPAGE; chg_cod_pag.attr_hdr.Attr_Size = sizeof (int); strncpy (chg_cod_pag.attr_hdr.Reserved, "\0\0\0", 4); chg_cod_pag.code_page = cpage; path_name.qlg_path_name.CCSID = 37; strncpy(path_name.qlg_path_name.Country_ID , "US", 2); /* !I18N */ strncpy(path_name.qlg_path_name.Language_ID, "ENU", 3); /* !I18N */ strncpy(path_name.qlg_path_name.Reserved, "\0\0", 3); path_name.qlg_path_name.Path_Type = 0; path_name.qlg_path_name.Path_Length = strlen(path); strncpy(path_name.qlg_path_name.Path_Name_Delimiter, "/", 2); strncpy(path_name.qlg_path_name.Reserved2, "\0\0\0\0\0\0\0\0\0", 10); strncpy(path_name.ifs_path, path, MIN(strlen(path), FILENAME_MAX)); /* Make the call */ result = Qp0lSetAttr((Qlg_Path_Name_T *) &path_name, (char *) &chg_cod_pag, sizeof(chg_cod_pag), QP0L_FOLLOW_SYMLNK); /* Return the result */ if (result) result = errno; return result; } int main (int argc, char *argv[]) { int result = 0; int codepage = 0; char * path = argv[1]; char * cp = argv[2]; if (argc < 3) { usage(argv); result = 1; } else { codepage = atoi(cp); printf( "path==%s, codepage==%d\n", path, codepage); result = chgcodepage(path, codepage); printf("result is %d.\n", result); } return result; } /* End of Program */